Hey, i’m new to JME3 as well as Java.I get a nullpointerexception when i try run a method from one class in the main class.
[java]package mygame;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.shape.Box;
import Gui.Menus;
import com.jme3.scene.Spatial;
public class Main extends SimpleApplication {
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
Menus menu = new Menus();
menu.Main(); // says something is wrong with this?
}
@Override
public void simpleUpdate(float tpf) {
//TODO: add update code
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}[/java]
[java]package Gui;
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.scene.Geometry;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Box;
import mygame.Main;
public class Menus extends SimpleApplication{
public void Main(){ // I want to use this method in main.java
Box box = new Box(Vector3f.ZERO, 2.5f,2.5f,1.0f);
Spatial wall = new Geometry(“Box”, box );
Material mat_brick = new Material(assetManager, “Common/MatDefs/Misc/Unshaded.j3md”); // says something is wrong with this?
wall.setMaterial(mat_brick);
wall.setLocalTranslation(2.0f,-2.5f,0.0f);
rootNode.attachChild(wall);
}
public void simpleInitApp(){
}
}[/java]
error
SEVERE: Uncaught exception thrown in Thread[LWJGL Renderer Thread,5,main]
java.lang.NullPointerException
at com.jme3.material.Material.(Material.java:116)
at Gui.Menus.Main(Menus.java:17)
at mygame.Main.simpleInitApp(Main.java:28)
at com.jme3.app.SimpleApplication.initialize(SimpleApplication.java:228)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.initInThread(LwjglAbstractDisplay.java:129)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:205)
at java.lang.Thread.run(Thread.java:722)
How can I get this to work?
I know I can use the niftyGui but I wanted to make a more 3d menu.