• Post Reply Bookmark Topic Watch Topic
  • New Topic

SWT: Nullpointer Exception when trying to dispose a composite

 
Andreas Balzer
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • 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:
 
Campbell Ritchie
Marshal
Posts: 52518
119
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Paper has not yet been outlawed – so let your Java Swing application print with wild abandon: JPDF
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!