• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SWT: Nullpointer Exception when trying to dispose a composite

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
If I try to dispose the composite "unten", I'll get a null pointer exception. I don't understand why it happens (lines 71, 75)

Here's the code:
 
Marshal
Posts: 79151
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please provide more details, eg, a marker to which line throws the error, and a copy of the exact error message.






You have declared unten twice; do a ctrl-F search for "unten" then "oben" and about L102 you declare unten anew as a local variable, which you don't do to oben. This mistake means that the field unten declared elsewhere is never initialised.

Go to your gewonnen and gelichstand methods and enter the following statements just before unten.dispose();

System.out.printf("Das Objekt \"unten\" gibt's doch: %b%n", unten != null);

which will probably print out the German for

"The object "unten" does exist after all: false"

If that is the problem, you can probably delete the "Composite" before "unten" on line 102 and sort out your Exception.
 
Andreas Balzer
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks! The second Composite unten was the reason. I took the local declaration out (which I forgot to do) and it works.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic