// 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,我真的不知道如何修复它们,任何请帮忙?