the code

Forum for J2ME mobile games related topics including programming doubts, books and other resources for J2ME game development

the code

Postby deepak_evil » Thu Aug 23, 2007 5:31 pm

Code: Select all
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class b extends Canvas implements Runnable {
    static final Font lowFont = Font.getFont(Font.FACE_MONOSPACE,Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
    static final Font highFont = Font.getFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, Font.SIZE_LARGE);
    static final int lowColor = 0x000000FF;
    static final int highColor = 0x00FF0000;
    static final int highBGColor = 0x00CCCCCC;
    static int width;
    Command cmd;
    static int height;
    static int startHeight;
    static final int spacing = highFont.getHeight() / 2;
    Image img;
    static final String[] mainMenu = {"New Game", "HighScore", "Settings", "Help", "About"};
    static int menuIdx;
    Thread menuThread;

    public b() {
        width = getWidth();
        height = getHeight();
        this.setFullScreenMode(true);
        cmd=new Command("deepak",Command.OK,0);
        startHeight = (highFont.getHeight() * mainMenu.length) + ((mainMenu.length - 1) * spacing);
        startHeight = (height - startHeight) / 2;
        try {
            img = Image.createImage("/a.png");
        } catch (Exception e) {
        }
        menuIdx = 0;
        menuThread = new Thread(this);
        menuThread.start();
    }

    public void run() {
        while (true) {
            repaint();
        }
    }

    public void paint(Graphics g) {
        g.setColor(255,255,255);
        g.fillRect(0, 0, width, height);
        g.drawImage(img, 40, getHeight() - 100, 0);
        for (int i = 0; i < mainMenu.length; i++) {
            if (i == menuIdx) {
                g.setColor(highBGColor);
                g.fillRect(0, startHeight + (i * highFont.getHeight()) + spacing, width, highFont.getHeight());
                g.setFont(highFont);
                g.setColor(highColor);
                g.drawString(mainMenu[i], (width - highFont.stringWidth(mainMenu[i])) / 2, startHeight + (i * highFont.getHeight()) + spacing, 20);
            } else {
                g.setFont(lowFont);
                g.setColor(lowColor);
                g.drawString(mainMenu[i], (width - lowFont.stringWidth(mainMenu[i])) / 2, startHeight + (i * highFont.getHeight()) + spacing, 20);
            }
        }
    }

    protected void keyPressed(int code) {
        if (getGameAction(code) == Canvas.UP && menuIdx - 1 >= 0) {
            menuIdx--;
        } else if (getGameAction(code) == Canvas.DOWN && menuIdx + 1 < mainMenu.length) {
            menuIdx++;
        }
        switch (code) {
            case FIRE:
                {
                    if (menuIdx == 0) {
                        display.setCurrent(nextScreen);
// This is where i get the Error the application throws a null pointer
// Exception and dies when i call the next Display on the screen which is a
// Game Canvas
                    } else if (menuIdx == 1) {
                        System.out.println("b");
                    } else if (menuIdx == 2) {
                        System.out.println("c");
                    } else if (menuIdx == 3) {
                        System.out.println("d");
                    } else if (menuIdx == 4) {
                        System.out.println("e");
                    }
                }
        }
    }
}
Deepak
deepak_evil
 
Posts: 37
Joined: Thu Aug 16, 2007 6:27 am

Postby DevelopmentTeam » Fri Aug 24, 2007 3:51 am

I doubt this is a simple mistake that you did not declare the nextscreen object or say the object is still a null and not yet constructed.
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Postby deepak_evil » Fri Aug 24, 2007 4:49 pm

i have declared the nextScreen in my code else it wont compile bcops i use netbeans and it shows an error that not the problem
Deepak
deepak_evil
 
Posts: 37
Joined: Thu Aug 16, 2007 6:27 am

Postby deepak_evil » Fri Aug 24, 2007 4:53 pm

i mean to say the problem is some thing else i have declared the next and previous screen in my code.
if i run those canvases individually . it runs perfectally
please have a closer look i think the problem is some thing else
Deepak
deepak_evil
 
Posts: 37
Joined: Thu Aug 16, 2007 6:27 am

Postby DevelopmentTeam » Fri Aug 24, 2007 4:56 pm

final silly question... did you mean you have writen
nextscreen = new NextScreen();
somewhere so that the object is initiallized...

only if you dont declare you get error...
private NextScreen nextscreen;
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Postby DevelopmentTeam » Fri Aug 24, 2007 4:57 pm

only if a variable is not initialized properly you will get nullpointerexception...
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Postby deepak_evil » Sat Aug 25, 2007 4:43 pm

please tell me another way to initalize a variable properlly or any other way to initillize the variable is the code ok
please rectify the code so it helps me the best
Deepak
deepak_evil
 
Posts: 37
Joined: Thu Aug 16, 2007 6:27 am

Postby DevelopmentTeam » Sun Aug 26, 2007 10:21 am

also check the display object if it is initialized or use Display class from the midlet to use it in the line where the problem comes... Incase this doesnt work either post the complete code of email me the code..
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

the code

Postby deepak_evil » Tue Aug 28, 2007 4:38 pm

i am still unable i will e-mail you my full code plz rectify the code and mail it back
Deepak
deepak_evil
 
Posts: 37
Joined: Thu Aug 16, 2007 6:27 am

Sprites

Postby deepak_evil » Tue Aug 28, 2007 4:42 pm

can any tell me where do i get good and free ware sprites that can be used in my game i am ready to give credits to that preson
Deepak
deepak_evil
 
Posts: 37
Joined: Thu Aug 16, 2007 6:27 am

Postby deepak_evil » Wed Aug 29, 2007 5:14 pm

i ahve already decalred the next screen but still i get null pointer exception
and my next displayable screen is not null as i run it individually(by declaring it in a midlet) it runns properlly

private NextScreen nextscreen;

nextscreen = new NextScreen();
on selecting the new game button the application calls the following screen but fails
display.setCurrent(nextScreen);
Deepak
deepak_evil
 
Posts: 37
Joined: Thu Aug 16, 2007 6:27 am

Postby DevelopmentTeam » Thu Aug 30, 2007 6:45 am

I didnt recieve your email yet... please send it to shankar [at] smackall [dot] com
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Postby DevelopmentTeam » Thu Aug 30, 2007 6:48 am

Form Game Sprite collections here is a list of links in this page which would help you

http://www.videogamesprites.net/Links/
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

sprite

Postby deepak_evil » Fri Aug 31, 2007 3:53 pm

are these sprites free to be used in the game too
Deepak
deepak_evil
 
Posts: 37
Joined: Thu Aug 16, 2007 6:27 am

Postby DevelopmentTeam » Sat Sep 01, 2007 4:01 am

for a commercial game we never use sprite from other games as anyway its illegal. In your case, check with your market and the scope of the project... but its always safe to use your own graphics.
User avatar
DevelopmentTeam
Site Admin
 
Posts: 661
Joined: Tue Aug 15, 2006 8:39 am
Location: India

Next

Return to J2ME Games

Who is online

Users browsing this forum: No registered users and 1 guest

cron