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 文件..按照这些步骤操作
你应该试试这个:
从 Java
所有对项目中project -> properties -> Java build path -> libraries
中删除JAR
的引用如果项目的根目录中不存在
libs
文件夹,请创建一个将JAR
复制到 libs 文件夹中。如果仍然没有运行正常。右键单击您的项目 > Android 工具 > 修复项目属性
清理你的项目并运行。它会起作用
关于android - Android 中的 ClassDefNotFound 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12511129/