java.lang.RuntimeException:执行doInBackground()时发生错误

时间:2012-07-07 07:43:25

标签: android android-asynctask

异常堆栈跟踪:

  

java.lang.RuntimeException:执行doInBackground()时发生错误   E / AndroidRuntime(695):在android.os.AsyncTask $ 3.done(AsyncTask.java:200)   E / AndroidRuntime(695):at java.util.concurrent.FutureTask $ Sync.innerSetException(FutureTask.java:273)   E / AndroidRuntime(695):at java.util.concurrent.FutureTask.setException(FutureTask.java:124)   E / AndroidRuntime(695):at java.util.concurrent.FutureTask $ Sync.innerRun(FutureTask.java:307)   E / AndroidRuntime(695):at java.util.concurrent.FutureTask.run(FutureTask.java:137)   E / AndroidRuntime(695):at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)   E / AndroidRuntime(695):at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:561)   E / AndroidRuntime(695):at java.lang.Thread.run(Thread.java:1096)   E / AndroidRuntime(695):引起:java.lang.NoClassDefFoundError:com.google.gson.Gson   E / AndroidRuntime(695):at com.amphisoft.mebox.LoginActivity $ LoginTask.doInBackground(LoginActivity.java:167)   E / AndroidRuntime(695):at com.amphisoft.mebox.LoginActivity $ LoginTask.doInBackground(LoginActivity.java:1)   E / AndroidRuntime(695):在android.os.AsyncTask $ 2.call(AsyncTask.java:185)   E / AndroidRuntime(695):at java.util.concurrent.FutureTask $ Sync.innerRun(FutureTask.java:305)   E / AndroidRuntime(695):... 4更多

这是我的代码:

protected User doInBackground(User... user) {
        HttpClient httpClient = new DefaultHttpClient();
        try {
            HashMap<String, String> parameters = new HashMap<String, String>();
            parameters.put("username", user[0].username);
            parameters.put("password", user[0].password);
            String response = HTTPUtil.post("/user/login.json", parameters,
                    null);
            System.out.println("Response:" + response);
            Gson gson = new Gson();
            User userObj = gson.fromJson(response, User.class);
            Store.getInstance().user = userObj;

        }

我尝试在库中多次添加gson-2.1jar ..但是没有找到与类定义相同的错误..请帮助我。提前谢谢..

1 个答案:

答案 0 :(得分:1)

创建一个libs文件夹并将 gson 放入其中,然后将该文件夹添加到库路径中。

请参阅this