当我运行以下代码时,应用程序崩溃
private void checkLogin(final String email, final String password) {
// Tag used to cancel the request
String tag_string_req = "req_login";
pDialog.setMessage("Logging in ...");
showDialog();
StringRequest strReq = new StringRequest(Request.Method.POST,
AppConfig.URL_REGISTER, 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);
// 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();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Login Error: " + error.getMessage());
Toast.makeText(getApplicationContext(),
error.getMessage(), Toast.LENGTH_LONG).show();
hideDialog();
}
}) {
@Override
protected Map<String, String> getParams() {
// Posting parameters to login url
Map<String, String> params = new HashMap<String, String>();
params.put("tag", "login");
params.put("email", email);
params.put("password", password);
return params;
}
};
// Adding request to request queue
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}
这是崩溃时的logcat响应
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: FATAL EXCEPTION: main
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: Process: com.security.amr.isk, PID: 20940
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: java.lang.IllegalStateException: Could not execute method of the activity
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at android.view.View$1.onClick(View.java:3858)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at android.view.View.performClick(View.java:4473)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:18472)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:733)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:136)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5021)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at android.view.View$1.onClick(View.java:3853)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at android.view.View.performClick(View.java:4473)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:18472)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:733)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:136)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5021)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: Caused by: java.lang.NullPointerException
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at com.security.amr.isk.LoginActivity.checkLogin(LoginActivity.java:202)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at com.security.amr.isk.LoginActivity.Login(LoginActivity.java:127)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at android.view.View$1.onClick(View.java:3853)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at android.view.View.performClick(View.java:4473)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at android.view.View$PerformClick.run(View.java:18472)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at android.os.Handler.handleCallback(Handler.java:733)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:95)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at android.os.Looper.loop(Looper.java:136)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:5021)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at java.lang.reflect.Method.invokeNative(Native Method)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at java.lang.reflect.Method.invoke(Method.java:515)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643)
10-08 14:20:41.853 20940-20940/? E/AndroidRuntime: at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:0)
在你的logcat中它说
<i>java.lang.NullPointerException 10-08 14:20:41.853 20940-20940/?<i>
E/AndroidRuntime: at
com.security.amr.isk.LoginActivity.checkLogin(LoginActivity.java:202)
10-08 14:20:41.853 20940-20940/?
E/AndroidRuntime: at
com.security.amr.isk.LoginActivity.Login(LoginActivity.java:127)
从这里我们可以说你有一个尚未分配的变量。检查你的登录方法或oncreate以查看你是否忘记初始化变量。更多信息我需要看到更多的代码配对。