Android Azure invokeApi获取空指针异常

史考特

我正在尝试在Azure移动服务上调用自定义API。我已经从我的应用程序成功完成此操作,因此我知道我已经正确设置了它。但是,在这种情况下,我从移动服务SDK中收到了一个空指针异常,因此我无法准确查明它发生的原因。(使用适用于Android的移动服务1.1.5)

来自Azure的日志表明服务器脚本正在成功运行。这是返回数据的脚本代码的片段:

          } else {
              console.log("no match");
              response.send(204, results);  //No Match
          }

这是我的Android应用程序中的invokeApi代码:

    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之前发生了错误,因为Log调用未反映在logcat输出中。我完全不知道为什么会这样。

卡洛斯菲盖拉

基于堆栈跟踪,它看起来像是Android SDK中的错误(处理204个响应-没有响应内容)。我猜想要解决此问题,您可以将状态码从204更改为200。

您可以在https://github.com/Azure/azure-mobile-services/issues上针对此问题提交错误根据您的评论,似乎仅针对200个响应正确解析了该响应,而其他响应可能包含更多数据。请注意,使用204表示将没有响应正文(根据定义-参见http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.4),但是您应该能够访问响应其他成功的状态代码。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章