gpt4 book ai didi

android - 使用 Volley 发布数据时发生错误 "NetworkDispatcher.run:Unhandled exception java.lang.NullPointerException: Attempt to invoke virtual method' "

转载 作者:太空狗 更新时间:2023-10-29 14:50:24 24 4
gpt4 key购买 nike

<分区>

错误“”NetworkDispatcher.run:未处理的异常 java.lang.NullPointerException:尝试调用虚拟方法 'int java.lang.String.length()'“”UI 包含两个密码编辑文本字段和一个按钮,我打算将用户输入的密码保存到服务器。但是当我单击提交按钮时,上述错误将由 StringRequest 的 onErrorResponce 函数显示。下面是将密码保存到服务器的代码。

  private void savePasswordToServer() {//pass1&pass are two edittext field objects
if(pass1.getText().toString().equals(pass.getText().toString()))
{
String url = new URLConstants().BaseURL+"save_password.php";
StringRequest request = new StringRequest(Request.Method.POST, url,new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try
{
JSONObject jsonObject = new JSONObject(response);
boolean e = jsonObject.getBoolean("error");
if(!e)
{
Toast.makeText(getApplicationContext(), "password change successful", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getApplicationContext(),HomeScreen.class);
startActivity(intent);
}
else
Toast.makeText(getApplicationContext(),jsonObject.getString("error_details"),Toast.LENGTH_LONG).show();
}catch (JSONException e)
{
Toast.makeText(getApplicationContext(),e.getMessage(),Toast.LENGTH_LONG).show();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(),"error VOLLEY "+error.getMessage(),Toast.LENGTH_LONG).show();
}
})
{
@Override
public Map<String, String> getParams()
{
Map<String, String> params = new HashMap<String, String>();
params.put("rollno",rollno);
params.put("password",pass1.getText().toString());
return params;
}
};
MySingleton.getInstance(this).addToRequestQueue(request);
}
else
{
pass1.setError("wrong password");
return;
}
}

下面是AndroiMonitor中产生的错误

03-12 11:35:55.020 2742-2803/? E/Volley: [155] NetworkDispatcher.run: Unhandled exception java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
at libcore.net.UriCodec.encode(UriCodec.java:132)
at java.net.URLEncoder.encode(URLEncoder.java:57)
at com.android.volley.Request.encodeParameters(Request.java:413)
at com.android.volley.Request.getBody(Request.java:399)
at com.android.volley.toolbox.HurlStack.addBodyIfExists(HurlStack.java:236)
at com.android.volley.toolbox.HurlStack.setConnectionParametersForRequest(HurlStack.java:210)
at com.android.volley.toolbox.HurlStack.performRequest(HurlStack.java:106)
at com.android.volley.toolbox.BasicNetwork.performRequest(BasicNetwork.java:93)
at com.android.volley.NetworkDispatcher.run(NetworkDispatcher.java:105)

请帮帮我

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com