uncaught exception thrown

8 replies [Last post]
Offline
Joined: 11/18/2012

uncaught exception thrown in thread main 5 main nullpointerexception would appear every time i included nifty in creating executable app. i tried to remove nifty and recreate the executable app and it would run perfectly fine but if i included the gui which is programmed using nifty the error would appear.

 

The gui would run perfectly with the game if it is run inside the bluej editor. i only encounter the problem if it is already finalized and builded as a execuble app.

 

Game.class code


import env3d.advanced.EnvAdvanced;
import env3d.EnvObject;
import com.jme3.cursors.plugins.JmeCursor;
 
public class Game{
    private EnvAdvanced env;
    private Room getRoom;
    private GameObject gameObject;
    private GameThread gameThread;
    private TimerThread timer;
   
    private final short screenWidth = 800;
    private final short screenHeight = 600;
   
    public static final byte roomWidth = 15;
    public static final byte roomHeight = 15;
    public static final byte roomDepth = 15;
   
    public static float height = 1.0f;
   
    public static byte stage = 1;
    public static byte sec = 0;
   
    public static byte score = 0;
   
    public static boolean isStageClear = false;
    public static boolean showGameScreen = false;
    public static boolean isThreadEnd = false;
    public static boolean endGame = false;
    public static boolean startThread = false;
 
    private boolean isHit = false;
   
    private EnvObject selected = null;

    public Game(){
        init();
    }
    public void play(){
           
        env.setResolution(screenWidth,screenHeight,24);
        env.getInputManager().setMouseCursor((JmeCursor)env.getAssetManager().loadAsset("cursor/Hammer_Hit.ani"));
       
        setGuiScreen();
       
        env.setRoom(getRoom);
       
        env.addObject(gameObject.getEnvObject());
       
        env.setCameraPitch(323.5);
        env.setCameraYaw(0);
        env.setCameraXYZ((roomWidth/2)+0.5,roomDepth-4,roomHeight*1.5);
       
        env.setDefaultControl(false);
        env.setShowStatus(true);
       
        gameThread = new GameThread(gameObject,env);
        timer = new TimerThread();
       
        env.soundLoop("sounds/mainBG.wav");
 
        while(!endGame){
           
            if(env.getKey() == 1){
                endGame = true;
            }
           
            if(isStageClear){
                isThreadEnd = true;
                showGameScreen = false;
                ScreenFactory.buildScreen("scoreScreen", new MyController(this,env), env.getNiftyGUI());
                env.getNiftyGUI().gotoScreen("scoreScreen");
                isStageClear = false;
                env.soundStop("sounds/BG.wav");
                env.soundLoop("sounds/scoreBG.wav");
            }
  
            if(showGameScreen){
               
                if(!startThread){
                    env.soundStop("sounds/mainBG.wav");
                    env.soundLoop("sounds/BG.wav");
                    gameThread.start();
                    timer.start();
                    startThread = true;
                }
               
                gameObject.setState(Tux.DANCE);
                gameObject.move();
               
                if(env.getMouseButtonClicked() == 0 && isHit){
                    env.soundPlay("sounds/hammerHit.wav");
                    env.soundPlay("sounds/tuxDie.wav");
                    score++;
                    isHit = false;
                    gameObject.setY(gameObject.getY()-100);
                }
                else if(env.getMouseButtonClicked() == 0){
                    env.soundPlay("sounds/crushedIce.wav");
                }
               
                checkHit();
                showStatus();
               
            }
           
            env.advanceOneFrame(60);
        }
        env.exit();
    }
    public void checkHit(){
        EnvObject pick = (EnvObject) env.getPick(env.getMouseX(),env.getMouseY());
        if(selected != pick){
            if(pick != null){
                isHit = true;
            }
            selected = pick;
        }
    }
    public void showStatus(){
        env.setDisplayStr("Stage: "+Byte.toString(stage),(screenWidth/2)-30,(screenHeight-screenHeight)+40,1.5,1,1,1,1);
        env.setDisplayStr("Score: "+score,30,screenHeight-30,1.5,1,1,1,1);
        env.setDisplayStr(Byte.toString(sec),screenWidth-50,screenHeight-30,1.5,1,1,1,1);
    }
   
    public void setGuiScreen(){
        // Build the screens, attach controller to the screen
        ScreenFactory.buildScreen("menuScreen", new MyController(this,env), env.getNiftyGUI());
        ScreenFactory.buildScreen("helpScreen", new MyController(this,env), env.getNiftyGUI());
        // Activate the screen
        env.getNiftyGUI().gotoScreen("menuScreen");
    }
    public void init(){
        env = new EnvAdvanced();
        getRoom = new Room(roomWidth,roomHeight,roomDepth);
        gameObject = new Tux((roomWidth/2),height,(roomDepth/2));
    }
    public static void main(String[] args){
        Game g = new Game();
        g.play();
    }
}

 

 

 

 

Offline
Joined: 12/13/2010
I assume this is on windows? 

I assume this is on windows?  I've never seen this as I usually developed on the mac.  I'll have to test it out next week when I get access to windows machines. 

One thing you can try in the meantime.  If you run the app from the command prompt, you may get the full stacktrace.  It would be intersting to see exactly where the error is being thrown.

 

Thanks, and looking forward to see your game in action!

 

Jason

Offline
Joined: 12/13/2010
Oh one more thing, if you use

Oh one more thing, if you use the Nifty.GUI example and package it as an exe, do you still get the NullPointerException?

Offline
Joined: 11/18/2012
Windows

Yes i use windows and the error will still appear if i use the nifty sample and build it as a runnable app.

 

Offline
Joined: 11/18/2012
 I tried to run it in

 I tried to run it in linux(Ubuntu 12.04) but the error would still appear but it would run fine without nifty

Offline
Joined: 11/18/2012
I tried to run it again on

I tried to run it again on windows using cmd and the result is


D:\env3d_template\dist>java env3d_template.jar
Error occurred during initialization of VM
java.nio.charset.UnsupportedCharsetException

 

Offline
Joined: 12/13/2010
I think that the command is

I think that the command is "java -jar env3d_template.jar"

Thanks for testing! I'll be able to try it out Thursday this week.

 

Offline
Joined: 12/13/2010
Ok, I think I found the

Ok, I think I found the problem! I accidentally excluded a bunch of important nifty files in the packaging process.  To temporarily fix this, replace the env3d_tempalte/build.xml file with the one attached to this post.  Then delete your env3d_template/build and env3d_template/dist directoies and try packaging it again.

AttachmentSize
build.xml 10.61 KB
Offline
Joined: 11/18/2012
Its working

 its working thank you so much. ill build the executable file in windows and ill run it on linux soon. the deadline of my project is today and im happy since the fix made it in time.