几天来我一直在尝试如何解决我的问题,但我没有成功。
我只是想执行 RESTlet HTTPS 请求。代码很简单,因为我只有一个 acritivity:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
System.setProperty("java.net.preferIPv6Addresses", "false");
Engine.getInstance().getRegisteredClients().clear();
Engine.getInstance().getRegisteredClients().add(new HttpsClientHelper(null));
System.out.println("VERIFICO IL TOKEN: ");
ClientResource clientResource = new ClientResource(
"https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=lalala");
Representation rep = clientResource.get();
}
restlet给出的原因是:
Caused by: Communication Error (1001) - Error while processing a connection
原因:
Caused by: java.lang.NullPointerException
at org.apache.harmony.xnet.provider.jsse.ClientSessionContext$HostAndPort.hashCode(ClientSessionContext.java:214)
at java.util.HashMap.put(HashMap.java:393)
我在网上读到它是一个 android 错误,但我找不到任何解决方法
任何想法?我正在使用 Restlet 2.1 RC5
完整的堆栈跟踪是:
08-19 13:43:23.911: E/AndroidRuntime(30053): FATAL EXCEPTION: main
08-19 13:43:23.911: E/AndroidRuntime(30053): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.helloandroid/com.example.helloandroid.MainActivity}: Communication Error (1001) - Error while processing a connection
08-19 13:43:23.911: E/AndroidRuntime(30053): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
08-19 13:43:23.911: E/AndroidRuntime(30053): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
08-19 13:43:23.911: E/AndroidRuntime(30053): at android.app.ActivityThread.access$2300(ActivityThread.java:135)
08-19 13:43:23.911: E/AndroidRuntime(30053): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
08-19 13:43:23.911: E/AndroidRuntime(30053): at android.os.Handler.dispatchMessage(Handler.java:99)
08-19 13:43:23.911: E/AndroidRuntime(30053): at android.os.Looper.loop(Looper.java:144)
08-19 13:43:23.911: E/AndroidRuntime(30053): at android.app.ActivityThread.main(ActivityThread.java:4937)
08-19 13:43:23.911: E/AndroidRuntime(30053): at java.lang.reflect.Method.invokeNative(Native Method)
08-19 13:43:23.911: E/AndroidRuntime(30053): at java.lang.reflect.Method.invoke(Method.java:521)
08-19 13:43:23.911: E/AndroidRuntime(30053): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
08-19 13:43:23.911: E/AndroidRuntime(30053): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
08-19 13:43:23.911: E/AndroidRuntime(30053): at dalvik.system.NativeStart.main(Native Method)
08-19 13:43:23.911: E/AndroidRuntime(30053): Caused by: Communication Error (1001) - Error while processing a connection
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.restlet.resource.ClientResource.doError(ClientResource.java:611)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.restlet.resource.ClientResource.handleInbound(ClientResource.java:1201)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.restlet.resource.ClientResource.handle(ClientResource.java:1068)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.restlet.resource.ClientResource.handle(ClientResource.java:1043)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.restlet.resource.ClientResource.handle(ClientResource.java:949)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.restlet.resource.ClientResource.get(ClientResource.java:657)
08-19 13:43:23.911: E/AndroidRuntime(30053): at com.example.helloandroid.MainActivity.onCreate(MainActivity.java:30)
08-19 13:43:23.911: E/AndroidRuntime(30053): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
08-19 13:43:23.911: E/AndroidRuntime(30053): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
08-19 13:43:23.911: E/AndroidRuntime(30053): ... 11 more
08-19 13:43:23.911: E/AndroidRuntime(30053): Caused by: java.lang.NullPointerException
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.apache.harmony.xnet.provider.jsse.ClientSessionContext$HostAndPort.hashCode(ClientSessionContext.java:214)
08-19 13:43:23.911: E/AndroidRuntime(30053): at java.util.HashMap.put(HashMap.java:393)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.apache.harmony.xnet.provider.jsse.ClientSessionContext.putSession(ClientSessionContext.java:190)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.apache.harmony.xnet.provider.jsse.ClientHandshakeImpl.unwrap(ClientHandshakeImpl.java:308)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.apache.harmony.xnet.provider.jsse.SSLRecordProtocol.unwrap(SSLRecordProtocol.java:413)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.apache.harmony.xnet.provider.jsse.SSLEngineImpl.unwrap(SSLEngineImpl.java:478)
08-19 13:43:23.911: E/AndroidRuntime(30053): at javax.net.ssl.SSLEngine.unwrap(SSLEngine.java:383)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.restlet.ext.ssl.internal.ReadableSslChannel.onDrain(ReadableSslChannel.java:114)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.restlet.engine.io.Buffer.process(Buffer.java:553)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.restlet.engine.io.Buffer.process(Buffer.java:668)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.restlet.engine.io.ReadableBufferedChannel.read(ReadableBufferedChannel.java:172)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.restlet.engine.io.Buffer.fill(Buffer.java:391)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.restlet.engine.connector.InboundWay.onFill(InboundWay.java:278)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.restlet.engine.io.Buffer.process(Buffer.java:597)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.restlet.engine.io.Buffer.process(Buffer.java:668)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.restlet.engine.connector.Way.processIoBuffer(Way.java:477)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.restlet.engine.connector.InboundWay.processIoBuffer(InboundWay.java:353)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.restlet.engine.connector.Way.onSelected(Way.java:430)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.restlet.engine.connector.ConnectionController.controlConnections(ConnectionController.java:105)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.restlet.engine.connector.ConnectionController.doRun(ConnectionController.java:156)
08-19 13:43:23.911: E/AndroidRuntime(30053): at org.restlet.engine.connector.Controller.run(Controller.java:158)
08-19 13:43:23.911: E/AndroidRuntime(30053): at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
08-19 13:43:23.911: E/AndroidRuntime(30053): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
08-19 13:43:23.911: E/AndroidRuntime(30053): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
08-19 13:43:23.911: E/AndroidRuntime(30053): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
08-19 13:43:23.911: E/AndroidRuntime(30053): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
08-19 13:43:23.911: E/AndroidRuntime(30053): at java.lang.Thread.run(Thread.java:1102)