1

在我的注销点击,

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 S 2 和 Galaxy Exhibit。

全文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)
"

我不知道那里发生了什么。

4

1 回答 1

2

我将从查看SettingsMainActivity.java文件中的第 63 行开始。根据堆栈跟踪,您将得到一个NullPointerException

Caused by: java.lang.NullPointerException
    at com.ecw.healow.settings.SettingsMainActivity.logOut(SettingsMainActivity.java:63)
    ...
于 2013-04-16T15:36:22.530 回答