android bad base64,android - java.lang.IllegalArgumentException: bad base-64 - Stack Overflow

开发者在使用Android Base64库进行字符串转换时遇到问题,尝试将double类型转换为字符串后进行Base64编码,导致IllegalArgumentException。已排除默认、NO_WRAP等编码方式,寻求解决思路。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

I am trying to encode and decode a String using android.util.Base64, but it gives a bad base-64 error.

The code with the problem is:

private byte[] base64ToByte(String str) throws IOException {

Log.i("encription", str);

byte[] returnbyteArray = Base64.decode(str, Base64.URL_SAFE);

return returnbyteArray;

}

The error logcat is:

08-09 13:02:18.589: E/AndroidRuntime(29827): Process: com.example.maptest, PID: 29827

08-09 13:02:18.589: E/AndroidRuntime(29827): java.lang.IllegalArgumentException: bad base-64

08-09 13:02:18.589: E/AndroidRuntime(29827): at android.util.Base64.decode(Base64.java:161)

08-09 13:02:18.589: E/AndroidRuntime(29827): at android.util.Base64.decode(Base64.java:136)

08-09 13:02:18.589: E/AndroidRuntime(29827): at android.util.Base64.decode(Base64.java:118)

08-09 13:02:18.589: E/AndroidRuntime(29827): at com.example.maptest.security.Encription.base64ToByte(Encription.java:116)

08-09 13:02:18.589: E/AndroidRuntime(29827): at com.example.maptest.security.Encription.encode(Encription.java:103)

08-09 13:02:18.589: E/AndroidRuntime(29827): at android.os.Handler.dispatchMessage(Handler.java:102)

08-09 13:02:18.589: E/AndroidRuntime(29827): at android.os.Looper.loop(Looper.java:136)

08-09 13:02:18.589: E/AndroidRuntime(29827): at android.app.ActivityThread.main(ActivityThread.java:5081)

08-09 13:02:18.589: E/AndroidRuntime(29827): at java.lang.reflect.Method.invokeNative(Native Method)

08-09 13:02:18.589: E/AndroidRuntime(29827): at java.lang.reflect.Method.invoke(Method.java:515)

08-09 13:02:18.589: E/AndroidRuntime(29827): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:781)

08-09 13:02:18.589: E/AndroidRuntime(29827): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)

08-09 13:02:18.589: E/AndroidRuntime(29827): at dalvik.system.NativeStart.main(Native Method)

The input(the str String from the code) looks like this:

08-09 13:02:18.539: I/encription(29827): 26.919047981500626

It is a double converted to a string, using:

String.valueOf(number)

The error is persistent with all encoding flags (DEFAULT, NO_WRAP, etc), any help would be apreciated, thank you.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值