尝试从原生Android应用程序中使用一些旧的AMF Web服务。 我包括了库:flex-messaging-core.jar和flex-messsaging-common.jar
Android活动中的代码:
AMFConnection amfConnection = new AMFConnection();
try{
String url = "http://example.com/cc/messagebroker/amf";
amfConnection.connect(url);
Object result = amfConnection.call("exampleService","foo", "bar");
textView.setText(result.toString());
} catch (Exception e) {
Log.e(TAG, e.getMessage(),e);
}
amfConnection.close();
完全相同的amf连接在Java SE中工作,可以得到正确的响应。但在Android中我得到例外:
java.lang.NullPointerException
at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:632)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:347)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296)
at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponseCode(HttpURLConnectionImpl.java:503)
at flex.messaging.io.amf.client.AMFConnection.generateHttpResponseInfo(AMFConnection.java:633)
at flex.messaging.io.amf.client.AMFConnection.call(AMFConnection.java:532)
at com.example.jamesjin.myapplication2.MainActivity.tryAMF(MainActivity.java:42)
at com.example.jamesjin.myapplication2.MainActivity.onCreate(MainActivity.java:33)
at android.app.Activity.performCreate(Activity.java:5451)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2298)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
at android.app.ActivityThread.access$900(ActivityThread.java:169)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1280)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:146)
at android.app.ActivityThread.main(ActivityThread.java:5487)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
at dalvik.system.NativeStart.main(Native Method)
我还试过klio-mobile-dataservice库,给出了同样的例外。
那么,如何解决此异常并从原生Android应用程序连接AMF Web Service?