i've made a simple frame with 2 labels, and and a JscrollPane, placed them in a GridBagLayout but everytime i try to run it, i get a nullpointerexception:
java.lang.NullPointerException
at Afbeelding.addComponent(Afbeelding.java:71)
at Afbeelding.<init>(Afbeelding.java:32)
at MyMenuBar.actionPerformed(MyMenuBar.java:60)
at java.awt.MenuItem.processActionEvent(MenuItem.java:588)
at java.awt.MenuItem.processEvent(MenuItem.java:548)
at java.awt.MenuComponent.dispatchEventImpl(MenuComponent.java:285)
at java.awt.MenuComponent.dispatchEvent(MenuComponent.java:273)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:452)
at java.awt.EventDispatchThread. pumpOneEventForHierarchy(EventDispatchTh
read.java:197)
at java.awt.EventDispatchThread. pumpEventsForHierarchy(EventDispatchThre
ad.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
the meaning is that Scrollpane stands under the reklabel, with the rightsite of the scrollpane just under the ":" from the text of the reklabel.
next to this their should be the other label, where the selected image off the scrollpane is displayed.
public static void main( String[] args)
{
Afbeelding application = new Afbeelding();
application.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
}
}
07-12-2004, 08:13 PM
cjard
there is not enough information to compile your code.. hence i cannot determine if your code and mine are the same.. your error message shows that an element on line 72 is null, but when i paste your code into my edotor and look at it.. 72 is a method declaration.. go and look at line 72 of your code (cos i dont have the right code from you).. on line 72m, one of the things you are using has been declared but not initialized.
i.e. this will give NullPointerException:
String nothing;
nothing.toCharArray(); //null pointer exception here