Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Array of Images - PLEASE HELP!

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I've been running around in circles with this - but no amount of advice seems to be getting it working!

PLEASE HELP!

My code produces 2 errors, for each of the six images (ie 12 in total):

they are:

1)



2)




Whatever I do I cannot fix these errors, where am I going wrong???
Please can someone post a fixed version as this is drving me crazy - I've been doing it for so long.

Thank-you greatly in advance for any help offered.

This is the seemingly simple code that is killing me:


 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, I'd like to ask you to read our naming policy and proceed to editing your display name into something compliant with the said policy.
Second, you are attempting to place expressions where only declarations can go. Consider the following:

Class "broken" is similar to what you are trying to do. I placed the executable code "sb.append("blah");" in the same place you are trying to initalize your arrays. You will get an "<identifier expected>" flagged on that line. Class "works1" demonstrates something called a static initializer block. The line "static {sb.append("blah");}" gets executed once, when the class is loaded. Note the "static" keyword and the enclosing braces. It will compile without error. Class works2 shows the typical way to do initialization, in a constructor.
 
Ranch Hand
Posts: 823
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So in your case you probably want to put the offending imageArray initialisation at the top of your init() method. You'll also need to import ImageObserver. I suggest that you make your imports specific rather than using *, which is just lazy and may lead to further troubles of the kind your currently having. You're only using 4 classes in that code fragment.

Would be nice if it said "statement where declaration should go error" though, eh?

Jules
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To be clear, note that Joe's "works1" example works if the initialization block is not static, or if sb is static. As is, it won't compile.
 
Don't touch me. And dont' touch this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic