Results 1 to 2 of 2
Thread: Null pointer exception
- 10-11-2012, 01:10 PM #1
Senior Member
- Join Date
- Aug 2011
- Posts
- 248
- Rep Power
- 2
Null pointer exception
Hello.
I'm trying to add to my JLabel array list a JLabel and I'm getting a null pointer exception.
Here is a piece of my code:
The exception happens in this line:Java Code:import java.applet.Applet; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.util.ArrayList; import javax.swing.*; public class Calculate extends Applet { private ArrayList<JLabel>label; private ArrayList<JButton>button; private ArrayList<JTextField>tfield; private GridBagConstraints c; public void init() { setLayout(new GridBagLayout()); c = new GridBagConstraints(); label.add(new JLabel("Your weight:")); c.gridx = 0; c.gridy = 0; add(label.get(0),c); } }label.add(new JLabel("Your weight:"));I know it's an applet but it's more a java syntax/coding question.java.lang.NullPointerException
at Calculate.init(Calculate.java:20)
at sun.applet.AppletPanel.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Thanks in advanced.
- 10-11-2012, 01:39 PM #2
Senior Member
- Join Date
- Aug 2011
- Posts
- 248
- Rep Power
- 2
Similar Threads
-
Null pointer Exception
By aortell24 in forum New To JavaReplies: 5Last Post: 07-20-2012, 11:38 PM -
Null pointer exception
By DBaskov in forum New To JavaReplies: 14Last Post: 07-10-2011, 11:16 PM -
Null pointer exception
By izzy in forum New To JavaReplies: 5Last Post: 03-22-2010, 05:19 PM -
null pointer exception
By jyothi.priyanka in forum New To JavaReplies: 12Last Post: 03-11-2009, 05:04 PM -
null pointer exception
By cityguy503@yahoo.com in forum New To JavaReplies: 4Last Post: 08-22-2008, 07:22 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks