Hello everyone,
My name is Norman I'm from Holland and I study Management Information Technology @ Hogeschool Arnhem Nijmegen. I'll make a good opening post in the right forum. But for now I've a beginners problem with a NullPointerException in a game I must create. I will explain it:
Error:
Here's my ClassCode:Start ruimte zoeken en x,y is 10,0
alles: 20,null
nullpointerexeption fout
java.lang.NullPointerException
at Bubblegame.Hangbubble.zoekRuimte(+137)
at Bubblegame.Hangbubble.<init>(+78)
at Bubblegame.Bubblegame.startGame(+52)
at Bubblegame.Bubblegame.menuAction(+61)
at phonegame.GameEngine$GameWindow.commandAction(+16)
at javax.microedition.lcdui.Display$DisplayAccessor.commandAction(+282)
at javax.microedition.lcdui.Display$DisplayManagerImpl.commandAction(+10)
at com.sun.midp.lcdui.DefaultEventHandler.commandEvent(+68)
at com.sun.midp.lcdui.AutomatedEventHandler.commandEvent(+47)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.handleVmEvent(+186)
at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+57)
I found as you can see that my 'mijnspel' has a null value when i run the game. Only I did declared it in my constructor right? I don;t see where this error exists.Code:public class Hangbubble extends Bubble{
[LEFT]
private int points;
public static int kleur;
private int x ;
private int y ;
private Bubblegame mijnspel;
public Hangbubble(Bubblegame mijnspel)
{
this.mijnspel = mijnspel;
System.out.println("Klasse hangbubble wordt aangeroepen " + mijnspel);
points = 20;
x=10;
y=0;
for (int i = 0; i< 23;i++ )
{
Bubble bb = new Bubble();
bb.kleurkiezen(mijnspel);
setImage(bb.s);
zoekRuimte();
bb.setPosition(x,y);
mijnspel.addGameItem(bb);
}
}
public void zoekRuimte()
{
int n=10;
System.out.println("Start ruimte zoeken en x,y is " + x + "," + y );
System.out.println("alles: " + points + "," + mijnspel );
if (mijnspel == null)
{
System.out.println ("nullpointerexeption fout");
}
while (mijnspel.findItemAt(x,y,getFrameWidth(),getFrameHeight()) != null )
{
x=x+n;
System.out.println("Iets gevonden");
zoekRuimte();
}
if (mijnspel.findItemAt(x,y,getFrameWidth(),getFrameHeight()) == null ) //Kijkt of er bubble op de x-as zit
{
if (mijnspel.findTilesAt (x,y,getFrameWidth(),getFrameHeight()) == 0 ) // Als er geen bubble op locatie ... zit dan wordt daar een bubble geplaatst
{
System.out.println("Coordinaten om te plaatsen" + getX() + "," + getY() );
x=getX();
y=getY();
}
else
{
x=10;
y=y+n;
zoekRuimte();
}
}
}[/LEFT]
Could anyone point me in the right direction, cause I'm trying hours and hours to solve it.
I would be very thankfull! :D:
Norman

