java.lang.NoClassDefFoundError (libgdx)

时间:2023-03-02
本文介绍了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.

这篇关于java.lang.NoClassDefFoundError (libgdx)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:无法将 gdx-tools 添加到 libgdx gradle 项目 下一篇:Java - LibGDX - isKeyPressed 和 isKeyJustPressed 有什么区别?

相关文章