Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

error in the code

Status
Not open for further replies.

Greenleaf

Programmer
Feb 14, 2002
93
IT
Hi, I have to complete a code. There's an array containing objects called fish. The method

Code:
 public void disegna(Graphics2D g, Applet parent);

is used to draw each fish in the array. I wrote the following piece of code:

Code:
 for ( int i=0 ; i < pesciArray.length; i++)
      {  ((OggettoAnimato) pesciArray[i]).disegna(Graphics2D g2, Applet parent);
      }

and when I compile it, it tells me that ')' is missing. As no ')' is missing, the mistake is of another nature. pelase help me!
 
If the array is defined as

OggettoAnimato[] pesciArray = new OggettoAnimato[your number of fish];

then there's no need to cast it. You can just call the method like this:

pesciArray.disegna(Graphics2D g2, Applet parent); &quot;When you have eliminated the impossible, whatever remains, however
improbable, must be the truth.&quot; ~ Arthur Conan Doyle
 
No, the array is defined as
Code:
 Object[] pesciArray
.
The method &quot;disegna&quot; is used for objects of OggettoAnimato so I must cast it.
 
I'm sorry, it's early in the morning....

Change

((OggettoAnimato) pesciArray).disegna(Graphics2D g2, Applet parent);

to simply

((OggettoAnimato) pesciArray).disegna(g2, parent); &quot;When you have eliminated the impossible, whatever remains, however
improbable, must be the truth.&quot; ~ Arthur Conan Doyle
 
idarke you are a dragon! thanks so much! If i have other problems i'll be back....that's a threat!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top