The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Java Help
|
Page 2 -
Updating JTextArea using Swing Timers
Page 2 - Discuss Updating JTextArea using Swing Timers in the Java Help forum on Dev Shed. Updating JTextArea using Swing Timers Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.
|
|
 |
|
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

December 4th, 2012, 02:17 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 14
Time spent in forums: 1 h 57 m 52 sec
Reputation Power: 0
|
|
|
How would I print out the value of Gooey() or of a JTextArea?
|

December 4th, 2012, 02:32 PM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
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:
Code:
System.out.println("an ID "+ <theVarNameHere>);
Last edited by NormR : December 4th, 2012 at 02:35 PM.
|

December 4th, 2012, 02:39 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 14
Time spent in forums: 1 h 57 m 52 sec
Reputation Power: 0
|
|
|
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
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
Quote: | There really arent any variables |
Post the contents of line 65 if you need help finding the variable(s) used on that line.
Quote: | proper way to reference an instance of another class |
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
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 14
Time spent in forums: 1 h 57 m 52 sec
Reputation Power: 0
|
|
If you look at my previous post, line 65 is:
Code:
testClass.setEventText();
Which is:
Code:
public void setEventText()
{
textArea.setText("test");
}
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).
|

December 4th, 2012, 03:11 PM
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
|
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
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 14
Time spent in forums: 1 h 57 m 52 sec
Reputation Power: 0
|
|
|
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
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
Quote: | reference the instance that was created in the other class |
Use the this variable to refer to the current class that the code is executing in.
Pass a reference:
Code:
refToAnotherClass.passRef(this); // pass a reference to this instance
|

December 4th, 2012, 03:43 PM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 14
Time spent in forums: 1 h 57 m 52 sec
Reputation Power: 0
|
|
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
|
 |
Contributing User
|
|
Join Date: Aug 2010
Location: SW Missouri
|
|
Glad you got it working.
Quote: | it was the null reference to my Gooey instance that was throwing the error |
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.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|