android - Android 中的 ClassDefNotFound 错误

标签 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();

我有这段代码,它返回“temp”字符串。我想将此字符串解析为 JSON 对象,并且还将 json-simple 1.1.1.jar 添加到我的引用库中。但是 classnotfound 错误和 classdefound 错误显示在日志 cat 中。如何解决?

最佳答案

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

你应该试试这个:

  1. 从 Java project -> properties -> Java build path -> libraries 中删除所有对项目中 JAR 的引用

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

  3. 如果仍然没有运行正常。右键单击您的项目 > Android 工具 > 修复项目属性

清理你的项目并运行。它会起作用

关于android - Android 中的 ClassDefNotFound 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12511129/

相关文章:

android - 移除 Android 应用标题栏

Android Camera.PreviewCallback 调度(使用 OpenGL 和 OpenCV)

android - CoordinatorLayout 留空底部空间

json - AFNetworking + JSON + 进度下载

android - Cardview 阴影未在 api 18 上正确显示

java - 为什么 BufferedReader.read(char[]) 似乎跳过字符,而 read() 却没有?

javascript - 基于日期的 meteor 查询

javascript - 连接到数据库时不显示 Google map

PHP数组到Json树格式

android - 如何将 iPhone 添加到 Android Studio?