0

There are traces:

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

When I run a Junit4 test class for Android project using Eclipse.The code is showed as below:

@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);    } 

And the method named "taskQueueToJson" was defined as below:

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();
}

How can I fix this problem,Thanks in advance!

6
  • stackoverflow.com/questions/6792197/… Commented May 3, 2016 at 4:00
  • Verify that all required libraries are included in the application’s classpath. The most common mistake is not to include all the necessary classes, before starting to execute a Java application that has dependencies on some external libraries. You might need to add json-x.x.jar here in your buildpath. Commented May 3, 2016 at 4:06
  • See this stackoverflow.com/questions/27504508/… Commented May 3, 2016 at 4:44
  • @Khuzi!buld path I have did it but it didn't work out. Commented May 3, 2016 at 6:06
  • !buld path I have did it but it didn't work out. @soorapadman Commented May 3, 2016 at 6:08

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.