Class Not Found

Hi all. Ok. I have been have been having this problem:

SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NoClassDefFoundError: BasicEnvironment/StaticTerrain
at Main.Main.setupTerrain(Main.java:139)
at Main.Main.simpleInitApp(Main.java:50)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:225)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:130)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:207)
at java.lang.Thread.run(Thread.java:619)
Caused by: java.lang.ClassNotFoundException: BasicEnvironment.StaticTerrain
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
… 6 more

I am not sure how this is possible because I have BasicEnvironment/StaticTerrain :-? . This is the third time this has happened. This error is like random sometimes it says some other class does not exist but it does exist. To fix this I make a new package and put the classes in there and then it works again but this is rather getting annoying -.- . Is there a solution for this?

This is the code for the Main class:
[java]

package Main;

import BasicCharacter.EnemyGenerator;
import BasicCharacter.Player;
import BasicEnvironment.Building;
import BasicEnvironment.StaticTerrain;
import BasicEnvironment.TowerGenerator;
import com.jme3.app.SimpleApplication;
import com.jme3.bullet.BulletAppState;
import com.jme3.font.BitmapText;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.niftygui.NiftyJmeDisplay;
import com.jme3.post.FilterPostProcessor;
import com.jme3.post.filters.BloomFilter;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import de.lessvoid.nifty.Nifty;

public class Main extends SimpleApplication {

Player player;
StaticTerrain dummyGround;
TowerGenerator towerGenerator;
EnemyGenerator enemyGenerator;
Building mainBuilding;

BulletAppState bulletAppState;

public static Nifty nifty;

public static void main(String[] args) {
    Main app = new Main();
    app.start();
}

@Override
public void simpleInitApp() {

// setDisplayFps(false);
setDisplayStatView(false);
viewPort.setBackgroundColor(new ColorRGBA(0.7f,0.8f,1f,1f));
flyCam.setMoveSpeed(30f);

    setupLight();
    setupBloom();
    setupTerrain();
    loadHUD();
    setupPlayer();
    setupBuilding();
    setupEnemy();
    setupTowerGenerator();
    setupCollision();

// setupAimTest();
}

private void setupAimTest() {
    guiNode.detachAllChildren();
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    BitmapText ch = new BitmapText(guiFont, false);
    ch.setSize(guiFont.getCharSet().getRenderedSize() * 2);
    ch.setText("+"); // crosshairs
    ch.setLocalTranslation( // center
      settings.getWidth() / 2 - guiFont.getCharSet().getRenderedSize() / 3 * 2,
      settings.getHeight() / 2 + ch.getLineHeight() / 2, 0);
    guiNode.attachChild(ch);
}

public void loadHUD(){
    flyCam.setDragToRotate(false);
    NiftyJmeDisplay niftyDisplay = new NiftyJmeDisplay(assetManager, 
                                                       inputManager,
                                                       audioRenderer,
                                                       guiViewPort);
    nifty = niftyDisplay.getNifty();
    nifty.fromXml("Interface/HUD.xml", "start");
    guiViewPort.addProcessor(niftyDisplay);
}

private void setupBuilding(){
    mainBuilding = new Building(assetManager, new Vector3f(-40, 0, 40), "Main", player);
    rootNode.attachChild(mainBuilding.rootNode);
}

private void setupTowerGenerator(){
    towerGenerator = new TowerGenerator(assetManager, enemyGenerator.enemy, nifty);
    
    //Enemy Generator setup
    enemyGenerator.setupTowerAndPlayer(towerGenerator.tower, player);
}

private void setupCollision(){
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);

// bulletAppState.getPhysicsSpace().enableDebug(assetManager); //<-----for debugging only
bulletAppState.getPhysicsSpace().add(player.physics);
bulletAppState.getPhysicsSpace().add(dummyGround.getPhysics());
bulletAppState.getPhysicsSpace().add(mainBuilding.rigidBody);
bulletAppState.getPhysicsSpace().add(mainBuilding.door1.rigidBody);

    //====Adding Enemy Bullet.CharacterControl
    for(int i = 0; i &lt; enemyGenerator.enemy.length; i++){
        bulletAppState.getPhysicsSpace().add(enemyGenerator.enemy[i].physics);
        for(int j = 0; j &lt; enemyGenerator.enemy[i].bulletGenerator.bullet.length; j++){
            bulletAppState.getPhysicsSpace().add(enemyGenerator.enemy[i].bulletGenerator.bullet[j].getPhysics());
        }
    }
    
    //====Adding Player Bullet.CharacterControl
    for(int i = 0; i &lt; player.yellowBullet.bullet.length; i++){
        bulletAppState.getPhysicsSpace().add(player.yellowBullet.bullet[i].getPhysics());
    }
    
    for(int i = 0; i &lt; player.blueBullet.bullet.length; i++){
        bulletAppState.getPhysicsSpace().add(player.blueBullet.bullet[i].getPhysics());
    }
}

private void setupEnemy(){
    enemyGenerator = new EnemyGenerator(assetManager, mainBuilding, nifty);
    
    for(int i = 0; i &lt; enemyGenerator.enemy.length; i++){
        rootNode.attachChild(enemyGenerator.enemy[i].rootNode);
    }
    
    //=======Send EnemyList to Player======//
    player.setupEnemyList(enemyGenerator.enemy);
}

private void setupPlayer(){
    player = new Player(assetManager, inputManager, new Vector3f(0, 2, 0), &quot;Player&quot;, nifty);
    rootNode.attachChild(player.rootNode);
}

private void setupTerrain(){
    dummyGround = new StaticTerrain(assetManager, Vector3f.ZERO, &quot;DummyGround&quot;);
    rootNode.attachChild(dummyGround.rootNode);
}

private void setupLight(){
    AmbientLight ambient = new AmbientLight();
    ambient.setColor(ColorRGBA.White);
    rootNode.addLight(ambient);  
    
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection((new Vector3f(-0.5f, -0.5f, -0.5f)).normalizeLocal());
    sun.setColor(ColorRGBA.White);
    rootNode.addLight(sun); 
}

private void setupBloom(){
    FilterPostProcessor fpp=new FilterPostProcessor(assetManager);
    BloomFilter bf=new BloomFilter(BloomFilter.GlowMode.Objects);
    fpp.addFilter(bf);
    viewPort.addProcessor(fpp);
}

@Override
public void simpleUpdate(float tpf){
    cam.setLocation(player.Update(cam.getDirection().clone().multLocal(0.4f), 
            cam.getLeft().clone().multLocal(0.2f), cam.getRotation(), tpf));
    UpdatesTower(tpf);
    UpdateEnemy(tpf);
    UpdateBuilding();
}

private void UpdateBuilding(){
    mainBuilding.Update();
}

private void UpdateEnemy(float tpf){
    enemyGenerator.Update(tpf);
    listener.setLocation(cam.getLocation());
    listener.setRotation(cam.getRotation());
}

private void UpdatesTower(float tpf){
    towerGenerator.Update(tpf);
    
    if(player.tower){
        player.tower = false;
        towerGenerator.addTower(player.physics.getPhysicsLocation(), cam.getDirection().clone());
        rootNode.attachChild(towerGenerator.getRootNode());
        bulletAppState.getPhysicsSpace().add(towerGenerator.getBodyPhysics());
        bulletAppState.getPhysicsSpace().add(towerGenerator.getTurrentPhysics());
        
        for(int i = 0; i &lt; towerGenerator.getTower().getBulletGenerator().bullet.length; i++){
            bulletAppState.getPhysicsSpace().add(towerGenerator.getBulletPhysics(i));
        }
    }
}

}

Did you clean&build some time?

Yes I did, but still does not work. This time it can not find any of the classes. So what i did was make a new project and copy paste src and asset folder to the new project and it works. But the issue still remains of that exception coming back after sometime. :expressionless:

Windows I gather? Did you try restarting the SDK? Do you use the jar libraries of that project outside of the project? Like if some other app opens these, windows will lock them and the SDK cannot read them.

Yes its windows. Yes I restarted the SDK. No I don’t use jar libraries outside of the project.

BasicEnvironment/StaticTerrain

Do you put your classes in a folder or a package?

Package.

Maybe its got something to do with the case of the package? As per the java spec only lower case names are allowed for packages.

In the package naming I give the first letter capital and the rest lower case. I don’t think package naming is the problem because it is working at first and after sometime it gives the problem. So, if package naming was the issue then the problem would have been given at the beginning rather than later.

Not really, if the OS registers different filenames based on case and at some point some script assumes your package names are lower case and converts some config file then not :slight_smile: Also I don’t know how the different classloaders handle this. But anyway I just wanted to give you something to try, not exchange hypotheses on processes.

I have been working with the game till now and didn’t get the problem yet. But when I do I will try your method and make the package name to lower case. It’s kool to try something new though :slight_smile: . Thanks Normen XD .

Lower case package names are a convention and not a language requirement. Even the guidelines tend to say “use lower case whenever possible”.

kool, didn’t notice the guidelines, will follow that then from now on. Good news is that I still haven’t got that problem yet but once I do I will make the changes.

Thanks all.

K Out!

I wanted to mention I just ran into this issue

[java]Exception in thread “main” java.lang.NoClassDefFoundError: mygame/planHead
at mygame.Main.<init>(Main.java:59)
at mygame.Main.main(Main.java:68)
Caused by: java.lang.ClassNotFoundException: mygame.planHead
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
… 2 more
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)[/java]

I just restarted my IDE and this came up…? Really annoying and upsetting. I wouldn’t have to restart if I wouldn’t keep getting “out of memory issues” I increased the heap size too…

I don’t know if it exactly happened after I restarted, because I went and reverted from my history after the edit, so Idk if that had anything to do with it?

My package name is “mygame,” which is the default I believe, as well as only using these files for this application/jar, etc.

I have tried resetting the ide multiple times, as well as clean and clean/build. I read up that it could be due to a pathing issue, but it seems to be okay, so I’m not sure what’s going on… really upsetting…

If your class name is really “planHead” with a lower case P then it’s named incorrectly. Maybe you have a typo somewhere? Or did you really name the class with a funny capitalization?

@pspeed said: If your class name is really "planHead" with a lower case P then it's named incorrectly. Maybe you have a typo somewhere? Or did you really name the class with a funny capitalization?

Yeah, I accidentally named it that way… I didn’t think that would mess it up… I had one called SimpleApp that also messed it up as well as “Vector3F,” is this named wrong? I did’t want “Vector3f” or something similar so after trying a few different times and a whole bunch of random errors occurred, then undid everything and it all works…

Achievement unlocked, we don’t ask questions LOL :).

Thank you as always!!!

EDIT: Another class “FlyCam” just did it as well, it seems to keep breaking every time i try to debug my code…"

It seems to “run” after I refactor, but now when I try to debug again
Njow I got a [java]
Apr 20, 2014 10:35:08 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NoSuchFieldError: flyCam[/java]

it seems to work after running it again… WEIRD…

There is something very wrong with your setup but I have no idea what it could be.

I’ve been developing this code for a long time, I don’t know what could have spurred this change, I didn’t do anything odd surrounding the issue, but all seems well now. I understanding the naming issue "not too sure why some of them went off when they were named correctly and Idk why it lasted so long as “planHead?”

Hve you tried, backing zup the pure src, killing all and reinstall the skd,
past code back into? That way you could rule out problems with the sdk installations. As this sounds kinde strange.

Hi all!

I just run into the same problem.

I’ve been working on a game since september and I use this class everytime I start up my game. About 30 minutes ago, my SDK failed to run my game due to lack of memory. So I restarted my pc to have a clean start, and when I hit run, the error above welcomes me. I was not able to run my game since pc restart because it tells me that my GameState class is missing, but I can confirm that it’s there, it has always been there (and will be) with the same package name.

Clean and rebuil doesn’t help.

[java]
Exception in thread “main” java.lang.NoClassDefFoundError: mygame/states/GameState
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2531)
at java.lang.Class.getMethod0(Class.java:2774)
at java.lang.Class.getMethod(Class.java:1663)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: mygame.states.GameState
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
… 6 more
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)
[/java]