android中的ClassDefNotFound错误

ssr*_*srp 2 android json

  new Thread(new Runnable() {
                public void run() {
                    HttpClient client = new DefaultHttpClient();
                    HttpConnectionParams.setConnectionTimeout(client.getParams(), 10000); //Timeout Limit
                    HttpResponse response;
                    JSONObject json = new JSONObject();
                    try{
                        HttpPost post = new HttpPost(URL);
                        post.setHeader("Content-type", "application/json");
                        json.put("username", userName);
                        json.put("password", password);
                        StringEntity se = new StringEntity( json.toString());
                        se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
                        post.setEntity(se);
                        response = client.execute(post);
                        /*Checking response */
                        if(response!=null){
                            String temp = EntityUtils.toString(response.getEntity()); //Get the data in the entity
                            JSONObject json2 = (JSONObject)new JSONParser().parse(temp);

                            //JsonObject o = new JsonParser().parse(temp).getAsJsonObject();
                            Log.v("response", json2.get("state").toString());
                    }}
                    catch(Exception e){
                        e.printStackTrace();
                        //createDialog("Error", "Cannot Estabilish Connection");
                    }
                }
              }).start();
Run Code Online (Sandbox Code Playgroud)

我有这个代码,这将返回"临时"字符串.我想将此字符串解析为JSON对象,并且还将json-simple 1.1.1.jar添加到我的refferenced库中.但是classnotfound错误和classdeffound错误出现在log cat中.怎么解决这个?

Raj*_*ddy 11

不要像这样添加jar文件.请按照这些步骤操作

你应该试试这个:

  1. Remove所有对JARJava项目的引用project -> properties -> Java build path -> libraries

  2. libs如果项目根目录中不存在,则创建一个文件夹将其复制JAR到libs文件夹中.

  3. 如果还没有运行OK.右键单击项目> Android工具>修复项目属性

清理你的项目并运行.它会工作