我想得到你的帮助,我试着宣布 “if(结果!= null&& result.contains(”login_ok“)){”,但应用程序回答错误传递,同样插入一个真正的传递。
logcat错误
03-31 09:16:51.509 20585-20585 / estudo.br.loginphpmysql E / AndroidRuntime:FATAL EXCEPTION:main进程:estudo.br.loginphpmysql,PID:20585
java.lang.NullPointerException:尝试在estudo.br.loginphpmysql.Login $ Askdata.onPostExecute(Login.java)的空对象引用上调用虚方法'boolean java.lang.String.contains(java.lang.CharSequence)'。 85)在
estudo.br.loginphpmysql.Login $ Askdata.onPostExecute(Login.java:72)at
android.os.AsyncTask.finish(AsyncTask.java:667)at
在左边的android.os.AsyncTask.-wrap1(AsyncTask.java)
android.os.AsyncTask $ InternalHandler.handleMessage(AsyncTask.java:684)在
android.os.Handler.dispatchMessage(Handler.java:102)at
在左边的android.os.Looper.loop(Looper.java:154)
android.app.ActivityThread.main(ActivityThread.java:6119)at
java中的java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:886)在
和类代码
public class Login extends AppCompatActivity {
EditText txtEmailL, txtPassL;
Button btnLogin;
String url = "";
String parameters= "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.login_activity);
txtEmailL = (EditText) findViewById(R.id.txtEmailL);
txtPassL = (EditText) findViewById(R.id.txtPassL);
btnLogin = (Button) findViewById(R.id.btnLogin);
}
public void txtforgot(View view) {
Intent intent = new Intent(Login.this, RedefinesPass.class);
startActivity(intent);
}
public void txtregister(View view) {
Intent intent = new Intent(Login.this, Register.class);
startActivity(intent);
}
public void btnlogin(View view) {
ConnectivityManager connMgr = (ConnectivityManager)
getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connMgr.getActiveNetworkInfo();
if (networkInfo != null && networkInfo.isConnected()) {
String email = txtEmailL.getText().toString();
String pass= txtPassL.getText().toString();
if (email.isEmpty() || pass.isEmpty()) {
Toast.makeText(getApplicationContext(), "fill in fields!", Toast.LENGTH_LONG).show();
} else {
parameters = "email= " + email + "&pass= " + pass
url = "http://localhost/logintest";
Askdata obj = new Askdata();
obj.execute(url);
}
} else {
Toast.makeText(getApplicationContext(), "No internet connection", Toast.LENGTH_LONG).show();
}
}
line 72 private class Askdata extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
return Connection.postDados(urls[0], parameters);
}
@Override
protected void onPostExecute(String result) {
line 85 if (result.contains("login_ok")) {
Intent inicio = new Intent(Login.this, MainScreen.class);
startActivity(inicio);
} else {
Toast.makeText(getApplicationContext(), "User or pass Wrong!", Toast.LENGTH_LONG).show();
}
}
}
@Override
protected void onPause(){
super.onPause();
finish();
}
}