December 4th, 2012, 02:17 PM
How would I print out the value of Gooey() or of a JTextArea?
December 4th, 2012, 02:32 PM
I'm not sure why you're interested in those items. Neither of them are variables.
The NPE is on line 65. You need to look at the variables on line 65 and find which one has a null value. Print it with something like this:
System.out.println("an ID "+ <theVarNameHere>);
Last edited by NormR; December 4th, 2012 at 02:35 PM.
December 4th, 2012, 02:39 PM
There really arent any variables, line 65 points to a method that calls setText but I did find that when I am trying to reference the instance of my Gooey that it is null. What is the proper way to reference an instance of another class? I think that is where my problem lies.
December 4th, 2012, 02:48 PM
Post the contents of line 65 if you need help finding the variable(s) used on that line.
By getting the address of the instance into a variable. The first reference will be returned by a new statement.
December 4th, 2012, 02:58 PM
If you look at my previous post, line 65 is:
testClass is null here. So I think I need to figure out how to properly reference the instance of testClass(which is instantiated in another class).
public void setEventText()
December 4th, 2012, 03:11 PM
the variable: testClass needs to have the address of an instance of the class: HelloWorldApp2. If an instance of the class already exists, then a reference tot the class should be passed in an arg to the class where its value is needed and saved there in a class variable.
If there isn't an instance of the class, then use a new statement to create the instance and get its address.
Last edited by NormR; December 4th, 2012 at 03:16 PM.
December 4th, 2012, 03:29 PM
Could you show me an example. I understand the logic but I'm having trouble with the syntax(or doing it properly I suppose). I can not create a new instance so I need to reference the instance that was created in the other class, but I'm unsure of how to do this. How would you reference the instance testClass from another class?
December 4th, 2012, 03:34 PM
Use the this variable to refer to the current class that the code is executing in.
Pass a reference:
refToAnotherClass.passRef(this); // pass a reference to this instance
December 4th, 2012, 03:43 PM
I didn't really understand the example but after hours of testing I finally am able to get things working correctly. Thanks for the help! (btw it was the null reference to my Gooey instance that was throwing the error )
December 4th, 2012, 03:56 PM
Glad you got it working.
Strange, I don't see any variables that hold a reference to an instance of the Gooey class.
Last edited by NormR; December 4th, 2012 at 03:58 PM.