This site requires JavaScript, please enable it in your browser!
Greenfoot back
frans.purple@gmail.com
frans.purple@gmail.com wrote ...

2013/8/20

Need reference

Hy all, when I develope the code, there are validation : "Cannot find symbol, method getExtendedKeyCodeForChar. What it should be ?
danpost danpost

2013/8/20

#
When you get 'Cannot find symbol, method ...', it means that the method given is not located in any classes that the object is part of. You may however, be referring to an object of the class the method is in, but the system, at the time, may only know the object to be of a superclass of that class; this would then require typecasting the reference to the class that the method is in. For example, let us say you have Actor subclasses called Ball and Block and you want the block to turn 90 degrees and flash when hit by the ball (you added a public void method in the Block class to perform the flashing). In the ball class:
Actor block = getOneInersectingObject(Block.class);
if (block != null)
{
    block.turn(90);
    block.flash(); // cannot find method occurs here
}
Since the field 'block' contains an Actor object (which happens to be a block, but not typecast to one), you get the error (line 4 works because the 'turn' method is in the Actor class). This can be fixed in one of the following ways:
// chande line 1 above to
Block block = (Block) getOneIntersectingObject(Block.class);
// or change line 5 to
((Block) block).flash();
By typecasting the field to a Block object, the system knows to also look in the Block class for the method.
erdelf erdelf

2013/8/20

#
your error should be fixed when you import the java.awt.event.KeyEvent class
You need to login to post a reply.