This site requires JavaScript, please enable it in your browser!
Greenfoot back
Redskins201054
Redskins201054 wrote ...

2012/4/10

java.langNullPointerException

Redskins201054 Redskins201054

2012/4/10

#
I currently have a world with all 26 letters in it. When i press that key on the keyboard the key changed to a "down" position(color). at the bottom of the screen there is a message that is supposed to change when all of the letters are pressed. The three classes are message, recorder and letter. I am currently trying to get the method keyPressed(string) from the recorder class to the letter class so that when i press the key on the keyboard the recorder records it. I currently have _recorder.keyPressed("S2"); in the act method of the letter class but am getting this run time error. Can someone help me out? thanks
Spilli Spilli

2012/4/10

#
Have you initialized the recorder class? Post your stack trace.
Redskins201054 Redskins201054

2012/4/10

#
java.lang.NullPointerException at Letter.act(Letter.java:118)
Spilli Spilli

2012/4/10

#
What's at line 118 in the Letter class?
Redskins201054 Redskins201054

2012/4/10

#
at greenfoot.core.Simulation.actActor(Simulation.java:507) at greenfoot.core.Simulation.runOneLoop(Simulation.java:470) at greenfoot.core.Simulation.runContent(Simulation.java:204) at greenfoot.core.Simulation.run(Simulation.java:194)
Redskins201054 Redskins201054

2012/4/10

#
i dont understand the 118 there isnt that many lines of code but i also have an error on line 40, and on line 40 i have _recorder.keyPressed("S2");
Spilli Spilli

2012/4/11

#
Does the keyPressed method use the Letter class?
Redskins201054 Redskins201054

2012/4/11

#
the keyPressed method is defined in the Recorder class. im having trouble getting it to work in the letter class so that the message will change when all 26 letters have been pressed on the keyboard
Spilli Spilli

2012/4/11

#
Obviously something is null, maybe you've forgot the initialize something or check if an instance is not null before using it.
danpost danpost

2012/4/11

#
I have a question: I understand that the letter class is the keyboard letters displayed on the screen, and the message class object is the ?user typed string? message displayed on the screen, but what is the recorder class for (is it something displayed on the screen, and if so, what does it display)? Yes, I'm fishing a bit, but it may be that you are making things more complicated than they have to be, and I'm just making sure.
ttamasu ttamasu

2012/4/11

#
I'm probably stating the obvious but let me get it straight: you have a instance of the class called _recorder and you initialized it like so : _ recoder = new Recorder(); // or something like this before you made the call: _recorder.keyPressed("S2"); right?
You need to login to post a reply.