开发者

java.lang.ArrayIndexOutOfBoundsException even after encoding a String in android app

开发者 https://www.devze.com 2023-04-11 19:41 出处:网络
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

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(6开发者_如何转开发363): 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


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.


The answer for this question is given by Maxim in the comments part. i have mentioned this here in order to close this question....

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号