我使用以下代码验证登录。大多数时候它的工作正常。但问题是有时会抛出异常。维护日志文件以捕获错误。当我检查日志文件时,它有" Err-CLS-Test - NULL"。以下是我的代码。怎么解决这个问题?
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);
}
});
}
下面是我的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