即使在 Android 应用程序中编码字符串后也会出现 java.lang.ArrayIndexOutOfBoundsException
在我的应用程序中,我尝试将电子邮件和密码发送到网址,作为回报,我用来获取成功消息或错误消息。当我点击 api 时,返回数据如下所示,
10-07 18:09:41.209: ERROR Data ?Error: Email and password do not match. Please try again!
10-07 18:10:47.698: ERROR Error(6363): java.lang.ArrayIndexOutOfBoundsException
问题是因为 Error 一词之前的 ?
所以我想到在我的代码中对返回数据进行编码,如下
HttpResponse rsp = client.execute(get);
tmpstr = URLEncoder.encode(EntityUtils.toString(rsp.getEntity()),"utf-8");
Log.e("Data ",""+tmpstr);
我在上面和下面尝试过方法
HttpResponse rsp = client.execute(get);
tmpstr = URLEncoder.encode(EntityUtils.toString(rsp.getEntity()),"utf-8");
Log.e("Data ",""+tmpstr);
String data = URLEncoder.encode(tmpstr,"UTF-8");
Log.e("returned dataaaaaaaaaaaaaaaaaaaaaaaaaa ",""+data);
在这两个代码中我都遇到相同的错误,如下所示
10-07 21:01:47.698: ERROR(6363): Data %EF%BB%BFError%3A+Email+and+password+do+not+match.+Please+try+again%21
10-07 21:01:47.698: ERROR(6363): java.lang.ArrayIndexOutOfBoundsException
如何解决此问题
in my app i am trying to send an email and password to an url and in return i use to get either success message or error message. When i hit the api the return data came as follows
10-07 18:09:41.209: ERROR Data ?Error: Email and password do not match. Please try again!
10-07 18:10:47.698: ERROR Error(6363): java.lang.ArrayIndexOutOfBoundsException
the problem is because of the ?
before the word Error
So i thought of encoding the return data in my code as follows
HttpResponse rsp = client.execute(get);
tmpstr = URLEncoder.encode(EntityUtils.toString(rsp.getEntity()),"utf-8");
Log.e("Data ",""+tmpstr);
i tried out in the above and below method
HttpResponse rsp = client.execute(get);
tmpstr = URLEncoder.encode(EntityUtils.toString(rsp.getEntity()),"utf-8");
Log.e("Data ",""+tmpstr);
String data = URLEncoder.encode(tmpstr,"UTF-8");
Log.e("returned dataaaaaaaaaaaaaaaaaaaaaaaaaa ",""+data);
In the both the codes i am getting the same error as follows
10-07 21:01:47.698: ERROR(6363): Data %EF%BB%BFError%3A+Email+and+password+do+not+match.+Please+try+again%21
10-07 21:01:47.698: ERROR(6363): java.lang.ArrayIndexOutOfBoundsException
how to solve this issue
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定必须使用
URLEncoder
对此类错误消息进行编码吗?我猜URLEncoder
需要一些类似于 URL 格式的字符串,而您传递的字符串看起来不像 url。Are you sure you have to use
URLEncoder
to encode such error messages? I guess theURLEncoder
expect some string formatted like URL, and the string that you pass doesn't looks like an url.这个问题的答案由Maxim在评论部分给出。我在这里提到这一点是为了结束这个问题......
The answer for this question is given by Maxim in the comments part. i have mentioned this here in order to close this question....