0
我正在使用JSON和MYSQL登錄應用程序它工作正常,如果我輸入用戶名和密碼的正確值,但每當我輸入一個無效的輸入它崩潰?Android登錄:應用程序崩潰時條目無效?
另一個奇怪的部分是,每當我登錄然後註銷,然後嘗試一個無效的條目,它使成功登錄。它就像它保存了以前的值,並且從不重置?
logcat的報告
09-22 18:52:26.838: E/AndroidRuntime(1924): FATAL EXCEPTION: main
09-22 18:52:26.838: E/AndroidRuntime(1924): Process: com.learn2crack.tab, PID: 1924
09-22 18:52:26.838: E/AndroidRuntime(1924): java.lang.NullPointerException
09-22 18:52:26.838: E/AndroidRuntime(1924): at com.learn2crack.tab.Login$ProcessLogin.onPostExecute(Login.java:202)
09-22 18:52:26.838: E/AndroidRuntime(1924): at com.learn2crack.tab.Login$ProcessLogin.onPostExecute(Login.java:1)
09-22 18:52:26.838: E/AndroidRuntime(1924): at android.os.AsyncTask.finish(AsyncTask.java:632)
09-22 18:52:26.838: E/AndroidRuntime(1924): at android.os.AsyncTask.access$600(AsyncTask.java:177)
09-22 18:52:26.838: E/AndroidRuntime(1924): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
09-22 18:52:26.838: E/AndroidRuntime(1924): at android.os.Handler.dispatchMessage(Handler.java:102)
09-22 18:52:26.838: E/AndroidRuntime(1924): at android.os.Looper.loop(Looper.java:136)
09-22 18:52:26.838: E/AndroidRuntime(1924): at android.app.ActivityThread.main(ActivityThread.java:5017)
09-22 18:52:26.838: E/AndroidRuntime(1924): at java.lang.reflect.Method.invokeNative(Native Method)
09-22 18:52:26.838: E/AndroidRuntime(1924): at java.lang.reflect.Method.invoke(Method.java:515)
09-22 18:52:26.838: E/AndroidRuntime(1924): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
09-22 18:52:26.838: E/AndroidRuntime(1924): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
09-22 18:52:26.838: E/AndroidRuntime(1924): at dalvik.system.NativeStart.main(Native Method)
互聯網連接後onclick事件的代碼片段檢查 login.java
/**
* Async Task to get and send data to My Sql database through JSON respone.
**/
private class ProcessLogin extends AsyncTask<String, String, JSONObject> {
private ProgressDialog pDialog;
String username,password;
@Override
protected void onPreExecute() {
super.onPreExecute();
inputusername = (EditText) findViewById(R.id.username);
inputPassword = (EditText) findViewById(R.id.pword);
username = inputusername.getText().toString();
password = inputPassword.getText().toString();
pDialog = new ProgressDialog(Login.this);
pDialog.setTitle("Contacting Servers");
pDialog.setMessage("Logging in ...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
@Override
protected JSONObject doInBackground(String... args) {
UserFunctions userFunction = new UserFunctions();
JSONObject json = userFunction.loginUser(username, password);
return json;
}
@Override
protected void onPostExecute(JSONObject json) {
try {
if (json.getString(KEY_SUCCESS) != null) {
String res = json.getString(KEY_SUCCESS);
if(Integer.parseInt(res) == 1){
pDialog.setMessage("Loading User Space");
pDialog.setTitle("Getting Data");
Intent upanel = new Intent(getApplicationContext(), MainActivity.class);
upanel.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
pDialog.dismiss();
startActivity(upanel);
/**
* Close Login Screen
**/
finish();
}else{
pDialog.dismiss();
loginErrorMsg.setText("Incorrect username/password");
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}
public void NetAsync(View view){
new NetCheck().execute();
}
}
從userfunctions.java登錄方法
public JSONObject loginUser(String email, String password){
// Building Parameters
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("tag", login_tag));
params.add(new BasicNameValuePair("email", email));
params.add(new BasicNameValuePair("password", password));
JSONObject json = jsonParser.getJSONFromUrl(loginURL, params);
return json;
是什麼線202? – panini 2014-09-22 23:40:01
它是「如果(json.getString(KEY_SUCCESS)!= null){」對不起,忘記提及 – user4068130 2014-09-22 23:43:31
json可能是null。你有沒有用調試器? – panini 2014-09-22 23:54:29