在我的登出点击,
public void logOut(View v){
LoggedInUser loggedInUser = CommonUtilities.getObjectFromSharedPreferances(this, Global.LOGGED_IN_HEALOW_USER, LoggedInUser.class);
CommonUtilities.updateDeviceSessionToServer(this, loggedInUser.getId(), "logout");
----Clearing SharedPreferance-----
}
我有一个类有一些静态实用程序方法。使用它们,我正在将会话更新到服务器&注销时清除共享首选项。CommonUtilities的实用方法getObjectFromSharedPreferances
如下:
public static <T> T getObjectFromSharedPreferances(Context context, String key, Class<T> returnType) {
Object obj = null;
Gson gson = new Gson();
SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
String jsonStr = settings.getString(key, null);
if (jsonStr != null) {
obj = gson.fromJson(jsonStr, returnType);
}
return returnType.cast(obj);
}
另一个实用程序方法updateDeviceSessionToServer
只是发送会话状态到服务器。
但是当执行updateDeviceSessionToServer
方法时,我得到异常。下面就是发生异常的(Line No 63)
行。
CommonUtilities.updateDeviceSessionToServer(this, loggedInUser.getId(), "logout");
同样,我没有得到所有设备的异常。这种情况正在某些设备上发生,比如Galaxy s2;星系展览。
完整stackstrace
如下:
"java.lang.IllegalStateException: Could not execute method of the activity
at android.view.View$1.onClick(View.java:2178)
at android.view.View.performClick(View.java:2574)
at android.view.View$PerformClick.run(View.java:9238)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at android.view.View$1.onClick(View.java:2173)
... 11 more
Caused by: java.lang.NullPointerException
at com.ecw.healow.settings.SettingsMainActivity.logOut(SettingsMainActivity.java:63)
... 14 more
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at android.view.View$1.onClick(View.java:2173)
at android.view.View.performClick(View.java:2574)
at android.view.View$PerformClick.run(View.java:9238)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.ecw.healow.settings.SettingsMainActivity.logOut(SettingsMainActivity.java:63)
... 14 more
java.lang.NullPointerException
at com.ecw.healow.settings.SettingsMainActivity.logOut(SettingsMainActivity.java:63)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at android.view.View$1.onClick(View.java:2173)
at android.view.View.performClick(View.java:2574)
at android.view.View$PerformClick.run(View.java:9238)
at android.os.Handler.handleCallback(Handler.java:587)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
at dalvik.system.NativeStart.main(Native Method)
"
我不明白这里发生了什么
我将从SettingsMainActivity.java
文件中的第63行开始。根据堆栈跟踪,您在那里得到了一个NullPointerException
:
Caused by: java.lang.NullPointerException
at com.ecw.healow.settings.SettingsMainActivity.logOut(SettingsMainActivity.java:63)
...