Jump to content
  • Advertisement
Sign in to follow this  
maximuz_2

[java] Help with my puzzle game

This topic is 4751 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

plz help me...heres the link for the source code to my puzzle game.. u will need wireless toolkit to run it.(just unrar it inside 'apps' folder of wireless toolkit--->sorry if u already know) http://www.geocities.com/maximuz_2/Tile.zip its in its infant stage and i m stuck... the game just reads key presses and moves the ball accordingly.It executes all rite but shows error randomly...(the dreaded Nullpointer again)Sometimes if i press keys quickly or other times simply unexpectedly. i believe it is abt freeing buffer memory as i am drawing graphics over already drawn 'offscreenbuffer'.....plz plz review and help me..

Share this post


Link to post
Share on other sites
Advertisement
I don't mean to be "mean" (geez, hope you get it), but I find it very hard that people will take their free time to browse your code and try to solve your problem for you.

So, please post the most important code snippets of your game, and point what you feel is wrong. Also, tell us the result of your own debugging - that will help us track the reason of your problems.

Use the "[ source lang="Java" ] [/source]" tag to post code inside cute text areas ;)

The NPE you talk about is the one from your other Thread, right?

Son Of Cain

Share this post


Link to post
Share on other sites
ya right i get it ..but when i posted a code piece last time somebody wanted the complete code thats y!!!
as far as my compiling, there is no error while compiling... just that the pgm gives error randomly while executing. what i need to know is whether there is
a function for cleaning an image buffer. in the earlier thread i was mentioning
the NPE while compiling but here it is encountered while executing.. hope u get my point..

here is my main application class:
[SOURCE LANGUAGE="Java" ] 
public class Tile extends MIDlet {
private Screen screen;
public Tile() {
screen = new Screen(this);
}


protected void destroyApp(boolean _boolean) throws
MIDletStateChangeException {
}

protected void pauseApp() {
}

protected void startApp() throws MIDletStateChangeException {
activateGameScreen();

}
public void activateGameScreen()
{
screen = new Screen(this);
Display.getDisplay(this).setCurrent(screen);
}

}
[/SOURCE]

and here is my screen class:
[SOURCE LANGUAGE="Java" ]
public class Screen extends Canvas {

private Tile theMidlet;
private Image offScreenBuffer;
byte tileMap[][];
int x1=0;int y1=0;
byte[][] level0 = {
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 1, 1, 1, 1, 1, 0, 0, 0, 0},
{0, 1, 0, 0, 0, 1, 0, 0, 0, 0},
{0, 1, 0, 0, 0, 1, 1, 1, 1, 0},
{0, 1, 0, 0, 0, 0, 0, 0, 1, 0},
{0, 1, 0, 0, 0, 0, 0, 0, 1, 0},
{0, 1, 0, 0, 0, 1, 1, 1, 1, 0},
{0, 1, 1, 1, 1, 1, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
};

public Screen(Tile midlet) {
theMidlet = midlet;
initResources();
}

protected void paint(Graphics graphics) {

renderWorld(x1,y1);
graphics.drawImage(offScreenBuffer, 0,0,Graphics.LEFT | Graphics.TOP);
//graphics.drawImage(img, 0,0,Graphics.LEFT | Graphics.TOP);
}

private void renderWorld(int px,int py) {
Graphics osg = offScreenBuffer.getGraphics();

osg.setColor(0x00444444);
osg.fillRect(0, 0, 180, 180);
for(int i=0;i<10;i++) {
for(int j=0;j<10;j++)
{
if(level0[j]==1){
osg.setColor(0x00209020);
int x=(j)*18;
int y=(i)*18;
osg.fillRect(x,y,18,18);
Image img = null;
try {
img = Image.createImage("C:\1.png");
} catch (IOException ex) {
}
osg.drawImage(img,px,py,Graphics.LEFT | Graphics.TOP);

}
}
}
}

private void initResources()
{
offScreenBuffer = Image.createImage(getWidth(), getHeight());
}
protected void keyPressed(int keyCode)
{
switch (getGameAction(keyCode))
{
case UP:
x1=x1+0;y1=y1-18;
break;
case DOWN:
x1=x1;y1=y1+18;
break;
case RIGHT:
x1=x1+18;y1=y1+0;
break;
case LEFT:
x1=x1-18;y1=y1+0;
break;
}
repaint();
}
}
[/SOURCE]

also my error is a little diff this time:]
[SOURCE LANGUAGE="Java" ]
java.lang.NullPointerException

at javax.microedition.lcdui.ImmutableImage.<init>(+11)

at javax.microedition.lcdui.Image.createImage(+8)

at Screen.renderWorld(+100)

at Screen.paint(+12)

at javax.microedition.lcdui.Canvas.callPaint(+80)

at javax.microedition.lcdui.Display.repaint(+78)

at javax.microedition.lcdui.Display$DisplayAccessor.repaint(+14)

at javax.microedition.lcdui.Display$DisplayManagerImpl.repaint(+16)

at com.sun.midp.lcdui.DefaultEventHandler.repaintScreenEvent(+25)

at com.sun.midp.lcdui.DefaultEventHandler$QueuedEventHandler.run(+775)
[/SOURCE]


[Edited by - maximuz_2 on October 11, 2005 11:44:18 PM]

Share this post


Link to post
Share on other sites
The NPE is definitely referring to statement img = Image.createImage("C:\1.png"); in renderWorld().

When I look at this statement, is it possible that it is returning a null object. If I remember about the drawImage() method, it will return a NPE if the Image object is null. Could it be that Image.createImage() works differently than you intended? I'm just asking because I don't really understand what string I should pass. Maybe the file doesn't exists and that Image.createImage() throws an IOException. If it does throw an IOException, then "img" might be null and it will be caught. You will be using it in the drawImage() method after the IOException is caught. Just a possibility.

Share this post


Link to post
Share on other sites
ya thats the thing... i was dumb enough to call createimage for each keypress(if u noticed)... so u got it right.. i tried to push up createimage above the pgm (above constructor) and succeeded!!! I solved the pblm myself.. but ur reply helped me to understand wat the error was and how my modification fixed it..... thanx unknownprodigy
thanx again...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!