java.lang.NoClassDefFoundError (libgdx)
一直在尝试使用 Libgdx 框架,但遇到了一些令人沮丧的问题.我正在学习教程,但无法运行我的项目.我做错了什么?
Been trying to work with the Libgdx framework and have been experiencing some frustrating issues.. I'm following a tutorial and I'm unable to run 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
}
}
这是我运行项目时控制台显示的内容:
Here's what the console displays when I run the project:
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
推荐答案
我遇到了同样的问题,但意识到我正在运行 GdxBuild.确保您右键单击 DesktopLauncher.java > Run As > Java Application.
I had the same problem, but realised that I was running GdxBuild instead. Ensure that you right click on DesktopLauncher.java > Run As > Java Application.
相关文章