對於android中的登錄頁面,我使用php webservice連接到服務器數據庫。我將來自php服務的響應存儲在一個字符串中。答案應該是成功或失敗。但有時候它既不會成功也不會失敗。所以當時它顯示空指針異常。我嘗試如下,但它是表示行空指針異常如何檢查一個字符串是否在android中返回null值?
如果(!response.equals(空)& & response.equals( 「SUCCESS」))
時響應是空的。我該如何解決這個問題。在這方面請幫助我。
if (!response.equals(null) && response.equals("SUCCESS")) {
Intent howis = new Intent(Login.this, Homepage.class);
startActivity(in);
}
else if (response.equals("FAILED")) {
new AlertDialog.Builder(Login1.this)
.setMessage(
"Sorry!! Incorrect Username or Password")
.setCancelable(false).setPositiveButton("OK", null)
.show();
password.setText("");
username.requestFocus();
} else if (response.equals(null)) {
new AlertDialog.Builder(Login1.this)
.setMessage("Invalid email or password")
.setCancelable(false).setPositiveButton("OK", null)
.show();
password.setText("");
username.requestFocus();
} else {
new AlertDialog.Builder(Login1.this)
.setMessage("Please Try Again..")
.setCancelable(false).setPositiveButton("OK", null)
.show();
password.setText("");
username.requestFocus();
}
(response == null || response ==「」) –
將其更改爲if(response!= null)&& response.equals(「SUCCESS」)) –