在安卓ClassDefNotFound错误错误、ClassDefNotFound

2023-09-12 06:43:36 作者:泪滴成冰

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

我有这个code和这个返回的温度字符串。我想分析该字符串以JSON对象,我还增加了JSON-简单1.1.1.jar我refferenced库。但ClassNotFound的错误和classdeffound错误显示在日志猫。如何解决呢?

I have this code and this returns the "temp" string. I wanted to parse this string to JSON object and I also added the json-simple 1.1.1.jar to my refferenced libraries. But the classnotfound error and classdeffound errors shows up in log cat. how to resolve this?

推荐答案

不要添加jar文件一样that..follow这些步骤

Don't add jar files like that..follow these steps

您应该试试这个:

删除从Java 项目中所有引用到项目的 JAR - >性能 - > Java构建路径 - >库

Remove all references to the JAR in your project from Java project -> properties -> Java build path -> libraries

创建一个文件夹,如果不是在你的项目中复制 JAR 的根到存在库文件夹。

Create a libs folder if not exist at the root of your project Copy the JAR into the libs folder.

如果仍然无法运行正常。右键单击您的项目>安卓工具>修复项目属性

If still not running OK. Right click your project > Android Tools > Fix Project Properties

清理项目并运行。它的工作

clean your project and run. it will work

 
精彩推荐
图片推荐