• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using .getText() and .append()

 
Joe Lank
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The purpose of this program is simple - input a string from a JTextField and append it to the end of a JTextArea. I'm getting null pointer exceptions when I try to use .getText, though. Is this a problem of scope?

 
Joe Ess
Bartender
Posts: 9362
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Joe Lank:
Is this a problem of scope?


Somewhat. You are declaring two variables called output and assigning a value to only one.
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In addition to shadowing the fields with local variables of the same name, you probably don't want to be using static field here. If created multiple instances of the tester class, all of the action events would append the text in the most recently constructed window to the the text area in the most recently constructed window (as opposed to the active window in where the event happened).
 
Joe Lank
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fixed, danke alle.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!