Java.lang.NoClassDefFoundError (libgdx)

I tried to work with the Libgdx database and experienced some unpleasant problems. I am following a tutorial and I cannot start my project. What am I doing wrong?

package com.mygdx.game.android; import com.badlogic.gdx.ApplicationListener; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; public class AndroidLauncher implements ApplicationListener { SpriteBatch batch; Texture mario; @Override public void create() { batch = new SpriteBatch(); mario = new Texture(Gdx.files.internal("mario.png")); } @Override public void resize(int width, int height) { // TODO Auto-generated method stub } @Override public void render() { Gdx.gl.glClearColor(1,1,1,1); batch.begin(); batch.draw(mario, 50, 50); batch.end(); } @Override public void pause() { // TODO Auto-generated method stub } @Override public void resume() { // TODO Auto-generated method stub } @Override public void dispose() { // TODO Auto-generated method stub } } 

The console is displayed here when the project starts:

 Exception in thread "main" java.lang.NoClassDefFoundError: com/badlogic/gdx/jnigen/NativeCodeGenerator at com.badlogic.gdx.utils.GdxBuild.main(GdxBuild.java:34) Caused by: java.lang.ClassNotFoundException: com.badlogic.gdx.jnigen.NativeCodeGenerator 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) ... 1 more 
+8
source share
7 answers

I had the same problem, but I realized that I was running GdxBuild instead. Make sure you right-click on DesktopLauncher.java> Run As> Java Application.

+7
source

In my case, this was my first libGDX project, I ran it using Android Studio version 3.0.1 on KUBUNTU, and as soon as I imported the newly created project using gdx-setup.jar (Setup App) into Android Studio, a pop-up message He asked me to update Gradle, which I did, and this broke the project.

enter image description here

Solution: create a new libGDX project and import it without updating Gradle (click " Don't remind me more about this project "), and it should work.

+3
source

Rigth click project-properties - build options - order and export and check all gdx libraries. This error probably occurs when it cannot find the class at runtime.

+2
source

I had the same problem, and the only way to reproduce it was using the desktop configuration. So instead of using the desktop configuration, run it as config gradle. On the command line, it will be:

 gradlew desktop:run 

Since this pain does manually every time you want to start a project, create a new gradle configuration

Click the plus sign and select

If you select the gradle project in the run configuration file, which is a helper module, all you need to enter is the gradlew run task instead of gradlew desktop:run .

You must define the memory flags in the VM parameter input (it is not necessary to have these values):

 -Xmx2G -Xms128M 
Options

Script may remain empty. Note that this whole thing is considered a gradle construct, so you need to kill the process (if it works) before you can start a new one.

I can export the jar without any problems, so you should be fine.

TL: DR; Use gradle run configuration with gradlew desktop:run instead of using application

+1
source

So many different answers. Instead of following them all, I created a new project. As simple as possible; if an IntelliJ update breaks my project, I want fewer unused features to be migrated in 2018

I was getting

java.lang.ClassNotFoundException: com.badlogic.gdx.ApplicationListener...

Caused by: java.lang.ClassNotFoundException: com.badlogic.gdx.ApplicationListener...

After upgrading IntelliJ from 2017.3 to 2018.1.

This time I did not check the opposite:

simplest libgdx setup

and similarly for the "Advanced" settings:

simplest advanced settings

Without choosing IDEA, the project took 10 seconds to generate and various instructions were given on how to import, which was noticeably more successful (the old ways were best remembered by someone Eclipse?).

Of course, I got a few more errors, but nothing that I had not encountered before, getting a new project from scratch. After that, you just need to copy the old files. Another tip, no matter what settings IntelliJ offers to open, to set the Java level to 1.7, the Gradle files do not touch, and therefore you must hunt for the remaining 1.6 links manually.

+1
source

Right-click β†’ Run As β†’ Run Configurations β†’ Click β€œDesktop” in the menu on the left, and then click β€œRun”, this should fix it.

0
source

Project structure β†’ modules β†’ select the required module (desktop, android, etc.) β†’ Dependencies β†’ Add library.

Remember to change the scope of the "Provided" to "Compile."

0
source

Source: https://habr.com/ru/post/973228/


All Articles