So I’m following a tutorial for a project I want to work on. The program has a private spacial getSpacial that gives me an illegal start of expression. I’ve tried everything I can to fix it but it’s still giving me problems:
Exception in thread “main” java.lang.ExceptionInInitializerError
Caused by: java.lang.RuntimeException: Uncompilable code - illegal start of expression
at mygame.Main.(Main.java:1)
/Users/davidlopez/Library/Caches/jmonkeyplatform/dev/executor-snippets/run.xml:111: The following error occurred while executing this line:
/Users/davidlopez/Library/Caches/jmonkeyplatform/dev/executor-snippets/run.xml:68: Java returned: 1
BUILD FAILED (total time: 4 seconds)
private Spatial getSpatial(String name) {
Node node = new Node(name);
// load picture
Picture pic = new Picture(name);
Texture2D tex = (Texture2D) assetManager.loadTexture("Textures/"+name+".png");
pic.setTexture(assetManager,tex,true);
// adjust picture
float width = tex.getImage().getWidth();
float height = tex.getImage().getHeight();
pic.setWidth(width);
pic.setHeight(height);
pic.move(-width/2f,-height/2f,0);
// add a material to the picture
Material picMat = new Material(assetManager, "Common/MatDefs/Gui/Gui.j3md");
picMat.getAdditionalRenderState().setBlendMode(BlendMode.AlphaAdditive);
node.setMaterial(picMat);
// set the radius of the spatial
// (using width only as a simple approximation)
node.setUserData("radius", width/2);
// attach the picture to the node and return it
node.attachChild(pic);
return node;
}
This error means, there is a Syntax error, for example using a wrong keyword or wrong closing brackets. The posted snipped is syntactic correct. Please post the whole class file, the mistake should be very easy to find.
import com.jme3.app.SimpleApplication;
import com.jme3.material.Material;
import com.jme3.material.RenderState.BlendMode;
import com.jme3.math.ColorRGBA;
import com.jme3.math.Vector3f;
import com.jme3.renderer.RenderManager;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.shape.Box;
import com.jme3.texture.Texture2D;
import com.jme3.ui.Picture;
/**
* This is the Main Class of your Game. You should only do initialization here.
* Move your Logic into AppStates or Controls
* @author normenhansen
*/
public class Main extends SimpleApplication {
public static void main(String[] args) {
Main app = new Main();
app.start();
}
@Override
public void simpleInitApp() {
// setup camera for 2D games
cam.setParallelProjection(true);
cam.setLocation(new Vector3f(0,0,0.5f));
getFlyByCamera().setEnabled(false);
// turn off stats view (you can leave it on, if you want)
setDisplayStatView(false);
setDisplayFps(false);
Box b = new Box(1, 1, 1);
Geometry geom = new Geometry("Box", b);
Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
mat.setColor("Color", ColorRGBA.Blue);
geom.setMaterial(mat);
rootNode.attachChild(geom);
private Spatial getSpatial(String name) {
Node node = new Node(name);
// load picture
Picture pic = new Picture(name);
Texture2D tex = (Texture2D) assetManager.loadTexture("Textures/"+name+".png");
pic.setTexture(assetManager,tex,true);
// adjust picture
float width = tex.getImage().getWidth();
float height = tex.getImage().getHeight();
pic.setWidth(width);
pic.setHeight(height);
pic.move(-width/2f,-height/2f,0);
// add a material to the picture
Material picMat = new Material(assetManager, "Common/MatDefs/Gui/Gui.j3md");
picMat.getAdditionalRenderState().setBlendMode(BlendMode.AlphaAdditive);
node.setMaterial(picMat);
// set the radius of the spatial
// (using width only as a simple approximation)
node.setUserData("radius", width/2);
// attach the picture to the node and return it
node.attachChild(pic);
return node;
}
@Override
public void simpleUpdate(float tpf) {
//TODO: add update code
}
@Override
public void simpleRender(RenderManager rm) {
//TODO: add render code
}
}
I assumed there was but i’m new to spatials and how they work but this is a 2d game so node is supposed to be my best bet.
thank you; i somehow didnt see that missing bracket. i have netbeans, should I use that?
also, what is the best way about approaching adding the player? the tutorial uses this method:
player.setUserData("alive",true);
player.move(settings.getWidth()/2, settings.getHeight()/2, 0);
guiNode.attachChild(player);
```
but i get an error saying it cannot find the symbol player because i have not started it
Yes, Netbeans is fine. If you don’t use it yet, you will may use the JME3 SDK. That is a modified Netbeans with additional functions like a scene composer for 3D scenes.
Since the tutorial uses the guiNode, I assume “player” should be a Picture type. Loading pictures is described here:
Yeah, especially if you are a beginner, well, anyone really that wants to be productive, use IDE. Any really. If you are a total beginner in Java, 3D and jME, you are in for some tough times. Not impossible of course. And for this target group I of course recommend jME SDK also.