• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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.
 
God is a comedian playing for an audience that is afraid to laugh - Voltair. tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic