File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Array of Images - PLEASE HELP! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array of Images - PLEASE HELP!" Watch "Array of Images - PLEASE HELP!" New topic

Array of Images - PLEASE HELP!

PM Knight

Joined: Aug 17, 2004
Posts: 2

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


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

they are:



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:

Joe Ess

Joined: Oct 29, 2001
Posts: 9189

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.

[How To Ask Questions On JavaRanch]
Julian Kennedy
Ranch Hand

Joined: Aug 02, 2004
Posts: 823
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?

Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
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.

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: Array of Images - PLEASE HELP!
It's not a secret anymore!