我在Runnable Class中运行以下代码并收到错误。代码和错误都在下面详述。
代码:
public class RunnableJob implements Runnable {
public Products products = new Products();
@Override
public void run() {
products
.productsField( "search", "iphone" );
/* Make the Request */
try {
JSONObject results = products.getProducts();
Log.i("System.out", results.getString("code"));
} catch (Exception e) {
e.printStackTrace();
Log.i("error", "hit the exception");
}
}
}
这是我们得到的错误:
07-17 12:16:51.766 11535-11550/com.example.jesarshah.snapcart E/AndroidRuntime﹕ FATAL EXCEPTION: Thread-197
Process: com.example.jesarshah.snapcart, PID: 11535
java.lang.NoSuchMethodError: No direct method <init>(Ljava/io/InputStream;)V in class Lorg/json/JSONTokener; or its super classes (declaration of 'org.json.JSONTokener' appears in /system/framework/core-libart.jar)
at com.semantics3.api.Semantics3Request.fetch(Semantics3Request.java:92)
at com.semantics3.api.Semantics3Request.runQuery(Semantics3Request.java:220)
at com.semantics3.api.Semantics3Request.get(Semantics3Request.java:263)
at com.semantics3.api.Semantics3Request.get(Semantics3Request.java:255)
at com.semantics3.api.Products.getProducts(Products.java:21)
at com.example.jesarshah.snapcart.RunnableJob.run(RunnableJob.java:30)
at java.lang.Thread.run(Thread.java:818)
答案 0 :(得分:0)
您依赖于旧版本的org.json(可能在某些其他包中也依赖于org.json)
我通过在pom.xml中明确定义依赖关系来解决这个问题
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20141113</version>
</dependency>
(如果您使用Maven以外的其他内容进行依赖关系管理,则需要进行类似的更改。)