Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
848 views
in Technique[技术] by (71.8m points)

json - ClassDefNotFound error in android

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

You should try this:

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

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

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

clean your project and run. it will work


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...