JSON-lib NoClassDefFoundError org.apache.commons.lang.exception.NestableRuntimeException

时间:2013-12-09 00:43:20

标签: java android mysql json apache

我正在尝试从我网站上的MySql数据库中检索一些数据。具体来说,我正在制作游戏(使用LibGDX框架),并希望从数据库中检索前10个高分。以下是处理JSON数据的代码部分

    JSONArray jArray = new JSONArray();
    jArray.add(result);
    for (int i = 0; i < jArray.size(); i++) {
        JSONObject jsonData = (JSONObject) jArray.get(i);
        System.out.printf("Name:%s \t Score: %d \n",
                jsonData.getString("name"), jsonData.getInt("score"));
    }

这是代码运行时出现的错误

Exception in thread "LWJGL Application" com.badlogic.gdx.utils.GdxRuntimeException: java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:120)
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(Unknown Source)
    at java.security.SecureClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.defineClass(Unknown Source)
    at java.net.URLClassLoader.access$100(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at com.me.gdxshooter.HighScores.readDatabase(HighScores.java:58)
    at com.me.gdxshooter.GameInstance.update(GameInstance.java:109)
    at com.me.gdxshooter.GameScreen.render(GameScreen.java:29)
    at com.badlogic.gdx.Game.render(Game.java:46)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication.mainLoop(LwjglApplication.java:207)
    at com.badlogic.gdx.backends.lwjgl.LwjglApplication$1.run(LwjglApplication.java:114)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.net.URLClassLoader$1.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
    at java.lang.ClassLoader.loadClass(Unknown Source)
    ... 18 more

这是我项目的类路径中所有jar的屏幕上限。 http://imgur.com/LYDisA3 任何帮助,将不胜感激!

2 个答案:

答案 0 :(得分:0)

试试这个:

转到项目/属性/ Java构建路径/订单和导出 - 如果您使用它,请确保在Android Dependencies和支持库前面进行检查。标记所有复选框并单击“应用”并清除项目。

希望这有帮助。

答案 1 :(得分:0)

我发现为了让json-lib工作,我需要在我的项目中引用以下内容:

  • Apache Commons BeanUtils 1.9.1
  • EZMorph 1.0.6
  • Apache Commons Collections 3.2.1