• Post Reply Bookmark Topic Watch Topic
  • New Topic

Null pointer exception error, Please help  RSS feed

 
William H Taylor
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This error message occurs when I try to pass a text area into a listener object. I have instantiated all objects so I shouldn't get the error. It is called in the action performed method, and it should be using the class instance variable after it is constructed. I tried instantiating in constructor and as member variable globally. Nothing works. I don't really understand what the problem is other than somehow it is making the inner class object before the outerclass. not possible. I am running windows xp pro, java6. Thank you in advance for the help.

 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi William.

You are using the subclass of KnowledgeListener eg InstructionListener. Now KnowledgeListener is abstract. I noticed in the InstructionListener or any concrete KnowledgeListener classes, where are the FileSaver and JTextArea parms coming from in order to call super()? Since all classes are public meaning in separate source files, these 2 parms can't be from the GUIInputter class. So you may need to change those concrete constructors of KnowledgeListener to pass in FileSaver and JTextArea too. Also where is the sentence variable coming from for the InterrogativeSentence class?

So it looks to me that any other 3 variables are null. You need to find out which one.

If you are in doubt in passing the parms correctly, try printing out the variables in the constructor/method of those action listeners.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't really understand what the problem is other than somehow it is making the inner class object before the outerclass. not possible.


How is it *not* possible? You are instantiating inner classes, which depends on variables, of the outer class, which you haven't instantiated yet -- so they are assigned to null. Now, you do complete initialization of the outer class later, but that is already too late for the inner class, as they got a copy of the null references.

Henry
 
William H Taylor
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for your help. I put a test for the JTextArea object in actionPerformed, and it works. It did not instantiate in the sequence I thought it would. I now have to work on the design. A thousand and three thank you's

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!