[Logo] JavaRanch » JavaRanch Saloon
  Search | FAQ | Recent Topics | Hot Topics
Register / Login


Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Beginning Java
 
RSS feed
 
New topic
Author

Null pointer exception error, Please help

William H Taylor
Greenhorn

Joined: Apr 22, 2009
Messages: 3

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
Ranch Hand

Joined: Sep 13, 2007
Messages: 884

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.

K. Tsang
SCJP5, SCJD
Henry Wong
author
Bartender

Joined: Sep 28, 2004
Messages: 10017

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

This message was edited 2 times. Last update was at by Henry Wong


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
William H Taylor
Greenhorn

Joined: Apr 22, 2009
Messages: 3

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
 
 
 
Reply Bookmark it! Watch this topic JavaRanch » Forums » Java » Beginning Java
 
RSS feed
 
New topic
IntelliJ open source

.