Android版的Azure invokeApi得到一个空指针异常 [英] Android Azure invokeApi getting a Null Pointer Exception
问题描述
我想打电话给在Azure移动服务定制API。我,所以我知道我已经正确设置它成功地从我的应用程序做到了这一点。然而,在这种情况下,我从移动服务中得到一个空指针异常SDK,所以我有它为什么发生的麻烦究竟跟踪。 (使用移动服务1.1.5 Android设备)
I'm trying to call a custom API on Azure Mobile Services. I've done this successfully from my app so I know I've set it up correctly. However in this case I'm getting a Null Pointer Exception from within the mobile services SDK so I'm having trouble tracing exactly why it's occurring. (using mobile services 1.1.5 for Android)
从Azure的日志表明服务器脚本运行成功。这里的脚本code,它的返回数据的片段:
The logs from Azure indicate that the server script is running successfully. Here's the snippet of script code that's returning data:
} else {
console.log("no match");
response.send(204, results); //No Match
}
下面是在我的Android应用程序的invokeApi code:
Here's the invokeApi code in my Android app:
mClient.invokeApi("data/check","GET",params,new ApiJsonOperationCallback() {
@Override
public void onCompleted(JsonElement jsonObject, Exception exception, ServiceFilterResponse response) {
Logg.d("onCompleted called successfully");
if (exception != null) {
if (response.getStatus().getStatusCode() == RESULT_OK) { //Item Already Exists
Logg.d("Match! Item Already Exists.");
} else if (response.getStatus().getStatusCode() == 206) { //Chain Match or partial chain match
Logg.d("Chain Match or partial Chain Match");
} else if (response.getStatus().getStatusCode() == 204) { //No match, request ok
Logg.d("No match found");
} else {
Logg.e("Azure exception: " + exception.getCause().getMessage());
result = RESULT_CANCELED;
}
}
}
});
和这里的错误堆栈:
12-27 08:39:21.497 13234-13234/com.farmsoft.lunchguru.app.debug W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x417b3da0)
12-27 08:39:21.537 13234-13234/com.farmsoft.lunchguru.app.debug E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.farmsoft.lunchguru.app.debug, PID: 13234
java.lang.NullPointerException
at java.io.StringReader.<init>(StringReader.java:47)
at com.google.gson.JsonParser.parse(JsonParser.java:45)
at com.microsoft.windowsazure.mobileservices.MobileServiceClient$5.onResponse(MobileServiceClient.java:708)
at com.microsoft.windowsazure.mobileservices.MobileServiceClient$6.onPostExecute(MobileServiceClient.java:825)
at com.microsoft.windowsazure.mobileservices.MobileServiceClient$6.onPostExecute(MobileServiceClient.java:1)
at android.os.AsyncTask.finish(AsyncTask.java:632)
at android.os.AsyncTask.access$600(AsyncTask.java:177)
at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
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)
看来,错误发生的前的onCompleted被称为因为日志的呼叫没有在logcat的输出反映出来。我不知所措,为什么是这样的话已经完全。
It seems that the error is occurring before onCompleted is called because the Log call is not reflected in the logcat output. I am completely at a loss to why this is the case.
推荐答案
根据堆栈跟踪它看起来像在Android SDK中的错误(涉及204回应 - 这没有响应的内容)。我猜,要解决此问题,你可以改变从204状态code至200。
Based on the stack trace it looks like a bug in the Android SDK (dealing with 204 responses - which do not have a response content). I'd guess that to workaround this issue you could change the status code from 204 to 200.
您可以在 https://github.com/Azure/azure-一个bug移动业务/问题此问题。看来,每次您的意见,该响应只被正确解析为200的反应,同时也有可能有更多的数据的其他反应。请注意,使用204意味着不会有任何响应体(根据定义 - 见的 http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.4 ),但你应该能够访问与其他成功状态codeS的响应。
You can file a bug at https://github.com/Azure/azure-mobile-services/issues for this issue. It seems, per your comments, that the response is only being parsed correctly for 200 responses, while there are other responses which could have more data. Notice that using 204 means that there will be no response body (by definition - see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.4), but you should be able to access the response with other successful status codes.
这篇关于Android版的Azure invokeApi得到一个空指针异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!