1

Good day. I need help to fix this error. When I try to login with empty username and password the app will not crush or stop. But when I input the username and password the app will crush or stopped.

LoginActivity.java

btnLogin.setOnClickListener(new View.OnClickListener() {

        public void onClick(View view) {
            String username = inputUsername.getText().toString().trim();
            String password = inputPassword.getText().toString().trim();

            // Check for empty data in the form
            if (!username.isEmpty() && !password.isEmpty()) {
                // login user
                checkLogin(username, password);
            } else {
                // Prompt user to enter credentials
                Toast.makeText(getApplicationContext(),
                        "Please enter the credentials!", Toast.LENGTH_LONG)
                        .show();
            }
        }

    });

private void checkLogin(final String username, final String password) {
    // Tag used to cancel the request
    String tag_string_req = "req_login";

    pDialog.setMessage("Logging in ...");
    showDialog();

    StringRequest strReq = new StringRequest(Method.POST,
            AppConfig.URL_LOGIN, new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            Log.d(TAG, "Login Response: " + response.toString());
            hideDialog();

            try {
                JSONObject jObj = new JSONObject(response);
                boolean error = jObj.getBoolean("error");

                // Check for error node in json
                if (!error) {
                    // user successfully logged in
                    // Create login session
                    session.setLogin(true);

                    // Now store the user in SQLite
                    //String uid = jObj.getString("uid");

                    JSONObject user = jObj.getJSONObject("user");
                    String br_code = user.getString("br_code");
                    String mem_id = user.getString("mem_id");
                    String username = user.getString("username");
                    String email = user.getString("email");
                    String created_at = user.getString("created_at");

                    // Inserting row in users table
                    db.addUser(br_code, mem_id, username, email, created_at);

                    // Launch main activity
                    Intent intent = new Intent(LoginActivity.this,
                            MainActivity.class);
                    startActivity(intent);
                    finish();
                } else {
                    // Error in login. Get the error message
                    String errorMsg = jObj.getString("error_msg");
                    Toast.makeText(getApplicationContext(),
                            errorMsg, Toast.LENGTH_LONG).show();
                }
            } catch (JSONException e) {
                // JSON error
                e.printStackTrace();
                Toast.makeText(getApplicationContext(), "Json error: " + e.getMessage(), Toast.LENGTH_LONG).show();
            }
        }

Logcat

05-23 12:16:28.740 16910-16910/? D/dalvikvm: Late-enabling CheckJNI
05-23 12:16:28.930 16910-16910/ph.coredev.johnjessbayutas.mobileportal E/Trace: error opening trace file: No such file or directory (2)
05-23 12:16:29.290 16910-16911/ph.coredev.johnjessbayutas.mobileportal D/dalvikvm: GC_CONCURRENT freed 110K, 7% free 6339K/6791K, paused 15ms+4ms, total 44ms
05-23 12:16:29.310 16910-16910/ph.coredev.johnjessbayutas.mobileportal D/libEGL: loaded /system/lib/egl/libEGL_VIVANTE.so
05-23 12:16:29.320 16910-16910/ph.coredev.johnjessbayutas.mobileportal D/libEGL: loaded /system/lib/egl/libGLESv1_CM_VIVANTE.so
05-23 12:16:29.340 16910-16910/ph.coredev.johnjessbayutas.mobileportal D/libEGL: loaded /system/lib/egl/libGLESv2_VIVANTE.so
05-23 12:16:29.420 16910-16910/ph.coredev.johnjessbayutas.mobileportal D/OpenGLRenderer: Enabling debug mode 0
05-23 12:16:37.610 16910-16910/ph.coredev.johnjessbayutas.mobileportal D/AndroidRuntime: Shutting down VM
05-23 12:16:37.610 16910-16910/ph.coredev.johnjessbayutas.mobileportal W/dalvikvm: threadid=1: thread exiting with uncaught exception (group=0x40acb300)
05-23 12:16:37.620 16910-16910/ph.coredev.johnjessbayutas.mobileportal E/AndroidRuntime: FATAL EXCEPTION: main
 java.lang.NullPointerException
     at ph.coredev.johnjessbayutas.mobileportal.Activity.LoginActivity.checkLogin(LoginActivity.java:187)
     at ph.coredev.johnjessbayutas.mobileportal.Activity.LoginActivity.access$200(LoginActivity.java:35)
     at ph.coredev.johnjessbayutas.mobileportal.Activity.LoginActivity$1.onClick(LoginActivity.java:83)
     at android.view.View.performClick(View.java:4084)
     at android.view.View$PerformClick.run(View.java:16966)
     at android.os.Handler.handleCallback(Handler.java:615)
     at android.os.Handler.dispatchMessage(Handler.java:92)
     at android.os.Looper.loop(Looper.java:137)
     at android.app.ActivityThread.main(ActivityThread.java:4746)
     at java.lang.reflect.Method.invokeNative(Native Method)
     at java.lang.reflect.Method.invoke(Method.java:511)
     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:917)
     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
     at dalvik.system.NativeStart.main(Native Method)
05-23 12:21:37.720 16910-16910/ph.coredev.johnjessbayutas.mobileportal I/Process: Sending signal. PID: 16910 SIG: 9

Im curious with this error 2nd line:

05-23 12:16:28.930 16910-16910/ph.coredev.johnjessbayutas.mobileportal E/Trace: error opening trace file: No such file or directory (2)
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
John
  • 25
  • 6
  • did you get json responce properly? – Learning Always May 23 '17 at 03:42
  • may be your error is in this line. you are adding inputs to database but it is not complete task and called another activity so ot will crash .db.addUser(br_code, mem_id, username, email, created_at); // Launch main activity Intent intent = new Intent(LoginActivity.this, MainActivity.class); startActivity(intent); finish(); – Learning Always May 23 '17 at 03:44
  • Trace file isn't the error... What do you not understand about nullpointerexception? – OneCricketeer May 23 '17 at 03:45
  • I'm new to android. I was just curious about the message error opening trace file: No such file or directory (2)... I only found this code in a tutorial and trying to follow whats in their and I change some code. I end up with this error.. Hope you will guide me how to fix this error nullpointerexception. – John May 23 '17 at 03:59
  • check the MainActivity.java, if is not exist register. – Jai Khambhayta May 23 '17 at 04:10

0 Answers0