This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
I get an NullPointerException when I try and call a append() or setText() method for a JTextArea but not a JTextField when everything else remains the same. Here is the revelant code.
Then from another class file.
As I said setting the JTextField works fine, but I get an NPE pointing at both references to the JTextArea, please someone tell me what I've done wrong. I'm using JCreator and XP.
Thanks,
Scott
[ June 11, 2005: Message edited by: scott beveridge ] [ June 11, 2005: Message edited by: scott beveridge ]
KR Campbell
Ranch Hand
Joined: Mar 26, 2004
Posts: 124
posted
0
Your problem is that you have two variables with the same name but different scope. You have instantiated the local version in createUserInterface() but not the instance variable. Thus, the local one hides the other one. Try:
instead of:
Regards Kenny
KR Campbell
Ranch Hand
Joined: Mar 26, 2004
Posts: 124
posted
0
... that is, it hides it within the scope of the method.
scott beveridge
Greenhorn
Joined: Mar 03, 2005
Posts: 11
posted
0
Thanks for the reply. This still does not work.
I originally had this but changed it because: When I try this now I get a compile error of
"cannot resolve symbol: auditJTextArea = new JTextArea();"
and of course everywhere that references it.
I've retyped "new JTextArea()" a thousand times but still no joy.
Scott
Ernest Friedman-Hill
author and iconoclast
Marshal
I don't know about "can't resolve symbol" errors, but you ought to get an "invalid type" error, because auditJTextArea is declared as a TextArea, but you're assigning a JTextArea to it -- those are two different classes.