-1
     // check for login response
            try {
                if (json.getString(KEY_SUCCESS) != null) {
                    Log.d("DEBUG", "jSON");
                      loginErrorMsg.setText("");

                    String res = json.getString(KEY_SUCCESS); 
                    if(Integer.parseInt(res) == 1){
                        // user successfully logged in
                        // Store user details in SQLite Database
                        DatabaseHandler db = new DatabaseHandler(getApplicationContext());
                        JSONObject json_user = json.getJSONObject("user");

                        // Clear all previous data in database
                        UserFunctions.logoutUser(getApplicationContext());
                        db.addSubscriber( json.getString(KEY_RegIDSubscribers), json_user.getString(KEY_EMAIL),json_user.getString(KEY_NAME), json_user.getString(KEY_Password), json_user.getString(KEY_Phone),json_user.getString(KEY_University),json_user.getString(KEY_Major), json.getString(KEY_GcmLocations));                        

                        // Launch Dashboard Screen
                        Intent dashboard = new Intent(getApplicationContext(), MainActivity.class);

                        // Close all views before launching Dashboard
                        dashboard.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(dashboard);

                        // Close Login Screen
                        finish();
                    }else{
                        // Error in login
                        loginErrorMsg.setText("Incorrect username/password");
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

我在“try”行开始出错,错误是 java.lang.NullPointerException ,我也得到 java.lang.String 无法转换为 JSONObject,我真的不知道如何修复它们,任何请帮忙?

4

1 回答 1

0

没有堆栈跟踪很难说,但我猜那loginErrorMsgnull. findViewById无论您在何处检索视图,都可能不会对其进行初始化,或将错误的 viewId 传递给方法。

于 2013-10-14T15:41:21.620 回答