• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

NPE with JTextArea

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

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 ]
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
... that is, it hides it within the scope of the method.
 
scott beveridge
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looking back at what Earnest said,



Here auditJTextArea has a reference type TextArea.



and here the runtime object for auditJTextArea is of type auditJTextArea.

Both TextArea and auditJTextArea belong to different class hierarchies, this gives a "Type Mismatch" compile time error.
 
scott beveridge
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah I've tried both TextArea and JTextArea, usually not at the same time (that doesn't work either).

I think the problem is a mistake in scope somewhere.
I'll keep trying and thanks for your input.

scott
 
What are you doing in my house? Get 'em tiny ad!
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic