我正在开发一个应用程序,我以配置文件的形式保存用户记录。
我将图像作为输入,然后使用 android 的内置转换功能将其转换为 base64 字符串。
byte[] b = baos.toByteArray();
final String imageText = Base64.encodeToString(b,Base64.URL_SAFE|Base64.No_WRAP);
并使用PHP代码将其发送到服务器并将其保存到MySQL数据库
MySQL 服务器
Engine is "MyISAM"
column type "text"
column collation "utf8_general_ci"
然后以 XML 的形式使用 PHP 进行检索。
在Android中,我正在解析XML并解码编码的字符串。
喜欢这个
byte[] decodedByte = Base64.decode(String,Base64.URL_SAFE|Base64.No_WRAP); b = BitmapFactory.decodeByteArray(decodedByte,0,decodedByte.length);
但有时它工作得很好,但有时我会得到
java.lang.IllegalArgumentException: bad base-64
at android.util.Base64.decode(Base64.java:161)
at android.util.Base64.decode(Base64.java:136)
at android.util.Base64.decode(Base64.java:118)
at...
请帮助我,我是安卓新手。
谢谢
像下面的代码一样使用 try-catch :
try{
byte[] b = baos.toByteArray();
final String imageText = Base64.encodeToString(b,Base64.URL_SAFE|Base64.No_WRAP);
}catch(Exception e){
Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
通过使用它,您将找到确切的错误。