0

I am using the below code to validate login. Most of the time its working fine. But the problem is sometimes it throws Exception. Am maintaining log file to capture error. When I check the Log file it has "Err-CLS-Test - NULL". Below is my code. How to solve this?

                mloginBtn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                try {

                        final String userName = mEdtTxtUserName.getText()
                                .toString();
                        String pswd = mEdtTxtPswd.getText().toString();

                                String uName = config.getSalesPersonCode();
                                String uPswd = config.getPassword();

                                if (userName.equalsIgnoreCase(uName)
                                        && pswd.equalsIgnoreCase(uPswd)) {
                                    mDbHelper.getReadableDatabase();
                                    String companyNo = mDbHelper.getCompanyCodeByName(companyName);
                                    mDbHelper.closeDatabase();
                                    mSupporter.setUsrCode(userName);
                                    mSupporter.setCompanyNo(companyNo);
                                    mSupporter.simpleNavigateTo(MainMenu.class);

                                } else {
                                    showAlert(
                                            "Enter valid User code and password.",
                                            "Invalid", R.drawable.warning);
                                    mloginBtn.setEnabled(true);
                                }

                            } 

                } catch (Exception exe) {
                    mToastMsg.showToast(LoginActivity.this, exe.getMessage());
                    exe.printStackTrace();
                    String errorCode = "Err-CLS-Test";
                    LogFileCreator.appendLog(errorCode + " : "
                            + exe.getMessage());
                    mloginBtn.setEnabled(true);
                }
});
    }

Below is my StackTrace

14:16:28 - java.lang.NullPointerException
    at com.visualqc.controller.LoginActivity$1.onClick(LoginActivity.java:176)
    at android.view.View.performClick(View.java:4222)
    at android.view.View$PerformClick.run(View.java:17337)
    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:4895)
    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:994)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
    at dalvik.system.NativeStart.main(Native Method)
 : null
Siva
  • 1,849
  • 2
  • 13
  • 28
  • Can you post the stack trace please? – elimirks Aug 03 '17 at 13:17
  • In development environment its working fine.. In the testing phase(in the device) its throwing exception.So I couldn't capture the stack trace. – Siva Aug 03 '17 at 13:30
  • See https://developer.android.com/studio/command-line/logcat.html for how to check exceptions – elimirks Aug 03 '17 at 13:39
  • sometime `Exception#getMessage()` returns null, use this answer to get full stacktrace as string and write it in your log. https://stackoverflow.com/a/1149712/3604083 – Yazan Aug 03 '17 at 13:41
  • I have added my stack trace – Siva Aug 08 '17 at 11:29

0 Answers0