Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Java - Keep getting NullPointerExemption
#3
I wish this was StackOverflow so I can edit your indentation, it's.. pretty bad.

Code:
JLabel[][] SkillLabels
int skill = 1;
while (skill < 4) {

    SkillLabels[skill][1] = new JLabel(SkillDatabase.Skills[1].getName());
    SkillLabels[skill][2] = new JLabel("Current Level:");
    SkillLabels[skill][3] = new JLabel("Current Stats:");
    SkillLabels[skill][4] = new JLabel(SkillDatabase.Skills[1].getDesc());

    LevelSkill[skill] = new JButton("Level Skill");
    LevelSkill[skill].addActionListener(this);
    skill++;
}

Anyway, a null pointer exception is a type of exception that happens when you have a reference type and do not initialize it, ergo it is "null".

Consider the following lines:
Code:
Integer x; //null
x = new Integer(42); //no longer null

So a null pointer exception happens when you try to dereference that null value.

Consider the following function:
Code:
public void myFunction(Integer x) {
    //do something with x here while x is null
    //NullPointerException thrown
}

Edit: Sapta has a point actually, I didn't notice that you didn't initialize your original SkillLabels. So there you go.
Reply


Messages In This Thread
Java - Keep getting NullPointerExemption - by Locked - 2013-02-24, 05:42 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)