Home > Net >  How to fix the Exception in thread "main" java.lang.Error: Unresolved compilation problem:
How to fix the Exception in thread "main" java.lang.Error: Unresolved compilation problem:

Time:12-19

I am a new java developer and I was writing some code and for some reason this error popped up:

Exception in thread "main" java.lang.Error: Unresolved compilation problem: 
    Syntax error, insert "}" to complete ClassBody

    at engineTester.MainGameLoop.main(MainGameLoop.java:109)

I don't understand what this error means and i have tried to look on reddit and stack overflow to see if anything could help me but i couldnt find anything to help me. If you could answer my question and say what i need to add it would be very helpful.

Here is my code:

package engineTester;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.lwjgl.opengl.Display;
import org.lwjgl.util.vector.Vector3f;

import entities.Camera;
import entities.Entity;
import entities.Light;
import entities.Player;
import models.RawModel;
import models.TexturedModel;
import renderEngine.DisplayManager;
import renderEngine.Loader;
import renderEngine.MasterRenderer;
import renderEngine.OBJLoader;
import terrains.Terrain;
import textures.ModelTexture;
import textures.TerrainTexture;
import textures.TerrainTexturePack;

public class MainGameLoop {

    public static void main(String[] args) {
        
        DisplayManager.createDisplay();
        Loader loader = new Loader();
        
        TerrainTexture backgroundTexture = new TerrainTexture(loader.loadTexture("grassy"));
        TerrainTexture rTexture = new TerrainTexture(loader.loadTexture("dirt"));
        TerrainTexture gTexture = new TerrainTexture(loader.loadTexture("pinkFlowers"));
        TerrainTexture bTexture = new TerrainTexture(loader.loadTexture("path"));
        
        TerrainTexturePack texturePack = new TerrainTexturePack(backgroundTexture, rTexture, 
                gTexture, bTexture);
        TerrainTexture blendMap = new TerrainTexture(loader.loadTexture("blendMap"));
        
        RawModel model = OBJLoader.loadObjModel("tree", loader);
        
        TexturedModel staticModel = new TexturedModel(model, new ModelTexture(
                loader.loadTexture("tree")));
        TexturedModel grass = new TexturedModel(OBJLoader.loadObjModel("grassModel", loader),
                new ModelTexture(loader.loadTexture("grassTexture")));
        TexturedModel fern = new TexturedModel(OBJLoader.loadObjModel("fern", loader),
                new ModelTexture(loader.loadTexture("fern")));
        TexturedModel bobble = new TexturedModel(OBJLoader.loadObjModel("lowPolyTree", loader),
                new ModelTexture(loader.loadTexture("lowPolyTree")));
        
        grass.getTexture().setHasTransparency(true);
        grass.getTexture().setUseFakeLighting(true);
        fern.getTexture().setHasTransparency(true);
        
        Light light = new Light(new Vector3f(20000, 20000, 20000), new Vector3f(1, 1, 1));
        
        Terrain terrain = new Terrain(0, -1, loader, texturePack, blendMap, "heightMap");
        
        List<Entity> entities = new ArrayList<Entity>();
        Random random = new Random(676452);
        for (int i = 0; i < 400; i  ) {
            if (i % 20 == 0) {
            float x = random.nextFloat() * 800 - 400;
            float z = random.nextFloat() * -600;
            float y = terrain.getHeightOfTerrain(x, z);
            entities.add(new Entity(fern, new Vector3f(x, y, z), 0, random.nextFloat() * 360,
                    0, 0.9f));
        }
        if (i % 5 == 0) {
            float x = random.nextFloat() * 800 - 400;
            float z = random.nextFloat() * -600;
            float y = terrain.getHeightOfTerrain(x, z);
            entities.add(new Entity(bobble, new Vector3f(x, y, z), 0, random.nextFloat() * 360,
                    0, random.nextFloat() * 0.1f   0.6f));
            x = random.nextFloat() * 800 - 400;
            z = random.nextFloat() * - 600;
            y = terrain.getHeightOfTerrain(x, z);
            entities.add(new Entity(staticModel, new Vector3f(x, y, z), 0, 0, 0, random.nextFloat() * 1   4));
        }
        
        MasterRenderer renderer = new MasterRenderer();
        
        RawModel bunnyModel = OBJLoader.loadObjModel("person", loader);
        TexturedModel stanfordBunny = new TexturedModel(bunnyModel, new ModelTexture(
                loader.loadTexture("playerTexture")));
        
        Player player = new Player(stanfordBunny, new Vector3f(100, 0, -50), 0, 180, 0, 0.6f);
        Camera camera = new Camera(player);
        
        while(!Display.isCloseRequested()) {
            camera.move();
            player.move(terrain);
            renderer.processEntity(player);
            renderer.processTerrain(terrain);
            for(Entity entity:entities){
                renderer.processEntity(entity);
            }
            renderer.render(light, camera);
            DisplayManager.updateDisplay(); 
        }
        
        renderer.cleanUp();
        loader.cleanUp();
        DisplayManager.closeDisplay();

    }

}

I have tried to do what the code error literally said but that did not work and I have tried looking around in my code but cant find anything else. If you could help your help would be greatly appreciated!

CodePudding user response:

Your for (int i = 0; i < 400; i ) { is not properly closed where you wanted it to be closed. It currently looks like this (when being properly formatted):

    for (int i = 0; i < 400; i  ) {
      if (i % 20 == 0) {
        float x = random.nextFloat() * 800 - 400;
        float z = random.nextFloat() * -600;
        float y = terrain.getHeightOfTerrain(x, z);
        entities.add(new Entity(fern, new Vector3f(x, y, z), 0, random.nextFloat() * 360,
                0, 0.9f));
      }
      if (i % 5 == 0) {
        float x = random.nextFloat() * 800 - 400;
        float z = random.nextFloat() * -600;
        float y = terrain.getHeightOfTerrain(x, z);
        entities.add(new Entity(bobble, new Vector3f(x, y, z), 0, random.nextFloat() * 360,
                0, random.nextFloat() * 0.1f   0.6f));
        x = random.nextFloat() * 800 - 400;
        z = random.nextFloat() * -600;
        y = terrain.getHeightOfTerrain(x, z);
        entities.add(new Entity(staticModel, new Vector3f(x, y, z), 0, 0, 0, random.nextFloat() * 1   4));
      }

      // !!! everything below here is STILL inside the for loop. !!!

      MasterRenderer renderer = new MasterRenderer();

      RawModel bunnyModel = OBJLoader.loadObjModel("person", loader);

You likely wanted to close the for-loop before:

      MasterRenderer renderer = new MasterRenderer();
  • Related