我收到一些用户的崩溃报告。报告:
java.lang.UnsupportedOperationException: JsonNull
at com.google.gson.JsonElement.getAsString(JsonElement.java:191)
at com.impact.ribony.LoginActivity$1.onCompleted(LoginActivity.java:115)
at com.impact.ribony.LoginActivity$1.onCompleted(LoginActivity.java:1)
at com.koushikdutta.async.future.SimpleFuture.handleCallbackUnlocked(SimpleFuture.java:107)
at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:141)
at com.koushikdutta.async.future.SimpleFuture.setComplete(SimpleFuture.java:128)
at com.koushikdutta.ion.IonRequestBuilder$1.run(IonRequestBuilder.java:242)
at com.koushikdutta.async.AsyncServer$RunnableWrapper.run(AsyncServer.java:53)
at android.os.Handler.handleCallback(Handler.java:733)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:212)
at android.app.ActivityThread.main(ActivityThread.java:5135)
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:877)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:693)
at dalvik.system.NativeStart.main(Native Method)
我的代码:
@Override
public void onCompleted(Exception e, JsonObject result) {
if (e == null) {
String anonId=result.get("anonid").getAsString();
}
}
我确定我的anonid
不是空的。为什么我收到此报告?
答案 0 :(得分:0)
这可能对您有用,请尝试一次。
anonId = result.get("anonid") != JsonNull.INSTANCE ? result.get("anonid").getAsString() : null;
或
anonId = !result.get("anonid").isJsonNull() ? result.get("anonid").getAsString() : null
答案 1 :(得分:0)
if (instance instanceof JsonNull) return true
为我工作