java.lang.NoClassDefFoundError:org / json / JSONException

时间:2016-05-03 03:58:10

标签: java android eclipse junit

有痕迹:

at com.tr.reader.test.HelperTest.test(HelperTest.java:45)   
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)  
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)  
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)  
at java.lang.reflect.Method.invoke(Unknown Source)  
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)     
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)  
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)   
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)    
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:27)  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)    
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)    
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)    
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)  
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)  
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)    
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)  
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)     
at org.junit.runners.ParentRunner.run(ParentRunner.java:363)    
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)  
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)   at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)   
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)   
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)    
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192) Caused by: java.lang.ClassNotFoundException: org.json.JSONException   
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)  
... 26 more

当我使用Eclipse运行Android项目的Junit4测试类时。代码如下所示:

@Test
public void test() {
    TaskQueue taskQueue = new TaskQueue();
    Task emtpy= new Task();
    emtpy.setTask_id(2);
    emtpy.setTime(System.currentTimeMillis());
    emtpy.setType(Task.EMTPY_TASK);
    taskQueue.add(emtpy);
    Task autoUpdate= new Task();
    AutoUpdate autoUpdate2 =  autoUpdate.new AutoUpdate();
    autoUpdate2.setVersion("21");
    autoUpdate2.setIp_list("192.168.2.30:8080,192.168.2.31:8080");
    autoUpdate2.setMd5("C97827C8D0956F7D");
    autoUpdate2.setDownload_url("api/dsa.apk");
    autoUpdate.setTask_id(3);
    autoUpdate.setTime(System.currentTimeMillis());
    autoUpdate.setType(Task.AUTO_UPDATE);
    taskQueue.add(autoUpdate);
    String taskQueueToJson = WJsonUtils.taskQueueToJson(taskQueue );
    Log.d("junit", taskQueueToJson);    } 

名为“taskQueueToJson”的方法定义如下:

public static String taskQueueToJson(TaskQueue taskQueue) {
    System.out.print("start");
    JSONArray jsonArray = new JSONArray();
    JSONObject taskObject = null;
    JSONObject autoObject = null;
    JSONObject scriptObject = null;
    AutoUpdate autoUpdate = null;
    Script script = null;
    Iterator<Task> iterator = taskQueue.iterator();
    Task task;
    int i = -1;
    try {
        while (iterator.hasNext()) {
            task = (Task) iterator.next();
            taskObject = new JSONObject();
            putJO(taskObject, "type", task.getType() + "");
            putJO(taskObject, "task_id", task.getTask_id() + "");
            putJO(taskObject, "time", task.getTime() + "");
            autoUpdate = task.getAutoUpdate();
            script = task.getScript();
            if (autoUpdate != null) {
                autoObject = new JSONObject();
                putJO(autoObject, "ip_list", autoUpdate.getIp_list());
                putJO(autoObject, "md5", autoUpdate.getMd5());
                putJO(autoObject, "download_url", autoUpdate.getDownload_url());
                putJO(autoObject, "version", autoUpdate.getVersion());
                System.out.print("autoUpdate");
                taskObject.put("auto_upate", autoObject);
            }
            if (script != null) {
                scriptObject = new JSONObject();
                putJO(scriptObject, "content", script.getContent());
                taskObject.put("script", script);
                System.out.print("script");
            }
            jsonArray.put(taskObject);
        }
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return jsonArray.toString();
}

如何解决此问题,提前致谢!

0 个答案:

没有答案