即使在 Android 应用程序中编码字符串后也会出现 java.lang.ArrayIndexOutOfBoundsException

发布于 2024-12-09 07:08:49 字数 1061 浏览 1 评论 0原文

在我的应用程序中,我尝试将电子邮件和密码发送到网址,作为回报,我用来获取成功消息或错误消息。当我点击 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

a√萤火虫的光℡ 2024-12-16 07:08:49

您确定必须使用 URLEncoder 对此类错误消息进行编码吗?我猜 URLEncoder 需要一些类似于 URL 格式的字符串,而您传递的字符串看起来不像 url。

Are you sure you have to use URLEncoder to encode such error messages? I guess the URLEncoder expect some string formatted like URL, and the string that you pass doesn't looks like an url.

入怼 2024-12-16 07:08:49

这个问题的答案由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....

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文