File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Null pointer exception error, Please help Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Null pointer exception error, Please help" Watch "Null pointer exception error, Please help" New topic
Author

Null pointer exception error, Please help

William H Taylor
Greenhorn

Joined: Apr 22, 2009
Posts: 14
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
Posts: 894

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 JavaRanch SCJD/OCM-JD
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 13401

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
Posts: 14
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
 
 
subject: Null pointer exception error, Please help
 
MyEclipse, The Clear Choice