0

正しいログインを使用すると正常に動作しますが、偽のログイン詳細でテストしようとすると、エラー メッセージが表示されません。代わりにクラッシュするだけです。

これがコードです

       public void onClick(View view) {
           String email = inputEmail.getText().toString();
           String password = inputPassword.getText().toString();
           UserFunctions userFunction = new UserFunctions();
           JSONObject json = userFunction.loginUser(email, password);

            //check for login response
           try {
               if (json.getString(KEY_SUCCESS) != null) {
                   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
                       userFunction.logoutUser(getApplicationContext());
                       db.addUser(json_user.getString(KEY_NAME), json_user.getString(KEY_EMAIL), json.getString(KEY_UID), json_user.getString(KEY_CREATED_AT));                        

                        //Launch Dashboard Screen
                       Intent dashboard = new Intent(getApplicationContext(), DashboardActivity.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();
           }
       }
   });

ここにログキャットがあります

FATAL EXCEPTION: main
 java.lang.NullPointerException
    at your.dissertation.project.LoginActivity$1.onClick(LoginActivity.java:62)
    at android.view.View.performClick(View.java:2533)
    at android.view.View$PerformClick.run(View.java:9320)
    at android.os.Handler.handleCallback(Handler.java:587)
    at android.os.Handler.dispatchMessage(Handler.java:92)
    at android.os.Looper.loop(Looper.java:150)
    at android.app.ActivityThread.main(ActivityThread.java:4385)
    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:849)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:607)
    at dalvik.system.NativeStart.main(Native Method)
4

1 に答える 1