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添加到了我的refferenced庫中。但是沒有發現classnotfound錯誤和classdeffound錯誤出現在log cat中。如何解決這個問題?Android中的ClassDefNotFound錯誤
你在項目中添加了jar文件 –
在這裏粘貼你的logcat。 – mihail
我通過項目屬性添加它 - >添加外部jar文件,它會自動轉到新創建的引用庫文件夾。 – ssrp