我使用OkHttp庫訪問URL ,我想返回時給出的消息顯示吐司。問題是,當我嘗試查看吐司時,顯示java.lang.NullPointerException
錯誤。你可以幫我嗎?顯示java.lang.NullPointerException展出吐司
對不起,我的英語不好。
public void sendtows(String usr_e, String usr_p) throws Exception{
String stResponse;
Request request = new Request.Builder()
.url("http://127.0.0.1/l.php?useremail=" + usr_e + "&userpassword=" + usr_p)
.build();
Response response = client.newCall(request).execute();
stResponse = response.body().string();
if(response.isSuccessful()){
if(stResponse.contains("OK")){
Log.d("Login", "Ok");
} else {
Toast toastErr = Toast.makeText(getApplicationContext(), "error", Toast.LENGTH_SHORT);
toastErr.show();
}
} else {
Log.d("ERRO", "erro");
}
}
你能發佈stacktrace? – jaudo
張貼你的日誌..... – Nithinlal
把你的logcat – Rustam