D
D
DoomSlayer2282021-05-27 14:08:47
Java
DoomSlayer228, 2021-05-27 14:08:47

How to fix "Unable to initialize main class" error in Eclipse when using LWJGL?

Tried to run some simple Java code using LWJGL in Eclipse:

import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;

public class Main {
  static int width = 800, height = 600;
  static DisplayMode mainDisplayMode = new DisplayMode(width, height);
  static boolean running = true;
  
  static void update() {
    if (Display.wasResized()) {
      width = Display.getWidth();
      height = Display.getHeight();
        	}
    Display.update();	    	
    		Display.sync(60);
    	
    if (Display.isCloseRequested()) {
        		running = false;
        	}
  }
  
  public static void main(String[] args) {
    try {
    Display.setLocation(
    (Display.getDesktopDisplayMode().getWidth() - mainDisplayMode.getWidth() / 2, 
    Display.getDesktopDisplayMode().getHeight() - mainDisplayMode.getHeight() / 2);
    		Display.setResizable(true);
            	Display.setVSyncEnabled(true);
        	Display.setDisplayMode(mainDisplayMode);
            	Display.create();
            
        } catch (LWJGLException ex) {
            	System.err.println(ex.getStackTrace().toString());
            	Display.destroy();
            	System.exit(1);
        }
    
    while (running) {
      
      update();
        }
        
        	Display.destroy();
        	System.exit(0);
  }
}

When run, it gives the error "Error: Unable to initialize main class main
Caused by: java.lang.NoClassDefFoundError". Tell me please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2021-05-27
Hasanly @azerphoenix

Error here:
public static void Main(String[] args) {
here Main is with a small letter.
public class main {
classes are named with a capital letter

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question