图像str = Base64.encodeBase64String(data)的异常;

时间:2014-09-09 19:43:36

标签: android image base64 android-camera nosuchmethoderror

每次当我尝试将我的字节数组转换为字符串时,我总是得到这个异常。 我直接从这个方法得到字节数组:

public void onPictureTaken(byte[] data, Camera arg1) {

            image_str = Base64.encodeBase64String(data);
}

这是我的日志:

        09-09 21:36:55.111: D/AndroidRuntime(21191): Shutting down VM
09-09 21:36:55.111: W/dalvikvm(21191): threadid=1: thread exiting with uncaught exception (group=0x410e02a0)
09-09 21:36:55.171: E/AndroidRuntime(21191): FATAL EXCEPTION: main
09-09 21:36:55.171: E/AndroidRuntime(21191): java.lang.NoSuchMethodError: org.apache.commons.codec.binary.Base64.encodeBase64String
09-09 21:36:55.171: E/AndroidRuntime(21191):    at de.sizuag.android.database.UploadImage.saveInstances(UploadImage.java:50)
09-09 21:36:55.171: E/AndroidRuntime(21191):    at de.sizuag.android.database.UploadImage.<init>(UploadImage.java:34)
09-09 21:36:55.171: E/AndroidRuntime(21191):    at de.sizuag.android.staff.extensions.NewProblem$3.onPictureTaken(NewProblem.java:129)
09-09 21:36:55.171: E/AndroidRuntime(21191):    at android.hardware.Camera$EventHandler.handleMessage(Camera.java:823)
09-09 21:36:55.171: E/AndroidRuntime(21191):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-09 21:36:55.171: E/AndroidRuntime(21191):    at android.os.Looper.loop(Looper.java:137)
09-09 21:36:55.171: E/AndroidRuntime(21191):    at android.app.ActivityThread.main(ActivityThread.java:4921)
09-09 21:36:55.171: E/AndroidRuntime(21191):    at java.lang.reflect.Method.invokeNative(Native Method)
09-09 21:36:55.171: E/AndroidRuntime(21191):    at java.lang.reflect.Method.invoke(Method.java:511)
09-09 21:36:55.171: E/AndroidRuntime(21191):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
09-09 21:36:55.171: E/AndroidRuntime(21191):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
09-09 21:36:55.171: E/AndroidRuntime(21191):    at dalvik.system.NativeStart.main(Native Method)
09-09 21:36:55.236: I/Process(21191): Sending signal. PID: 21191 SIG: 9
09-09 21:36:55.466: D/dalvikvm(21513): GC_FOR_ALLOC freed 75K, 14% free 9420K/10883K, paused 22ms, total 29ms
09-09 21:36:55.466: I/dalvikvm-heap(21513): Grow heap (frag case) to 11.825MB for 1439956-byte allocation
09-09 21:36:55.501: D/dalvikvm(21513): GC_CONCURRENT freed <1K, 12% free 10825K/12295K, paused 11ms+1ms, total 37ms
09-09 21:36:55.591: D/dalvikvm(21513): GC_FOR_ALLOC freed 0K, 12% free 10825K/12295K, paused 20ms, total 20ms
09-09 21:36:55.591: I/dalvikvm-heap(21513): Grow heap (frag case) to 14.917MB for 3243524-byte allocation
09-09 21:36:55.631: D/dalvikvm(21513): GC_CONCURRENT freed 0K, 10% free 13993K/15495K, paused 12ms+1ms, total 40ms
09-09 21:36:55.711: D/libEGL(21513): loaded /system/lib/egl/libEGL_mali.so
09-09 21:36:55.716: D/libEGL(21513): loaded /system/lib/egl/libGLESv1_CM_mali.so
09-09 21:36:55.716: D/libEGL(21513): loaded /system/lib/egl/libGLESv2_mali.so
09-09 21:36:55.721: D/(21513): Device driver API match
09-09 21:36:55.721: D/(21513): Device driver API version: 10
09-09 21:36:55.721: D/(21513): User space API version: 10 
09-09 21:36:55.721: D/(21513): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Thu Oct 25 08:43:05 KST 2012 
09-09 21:36:55.736: D/OpenGLRenderer(21513): Enabling debug mode 0

这是我的新Log ...添加Base64Encode

之后
09-09 22:37:38.766: E/dalvikvm(25990): Could not find class 'Decoder.BASE64Encoder', referenced from method de.sizuag.android.database.UploadImage.saveInstances
09-09 22:37:38.766: W/dalvikvm(25990): VFY: unable to resolve new-instance 6 (LDecoder/BASE64Encoder;) in Lde/sizuag/android/database/UploadImage;
09-09 22:37:38.766: D/dalvikvm(25990): VFY: replacing opcode 0x22 at 0x0002
09-09 22:37:43.026: D/dalvikvm(25990): DexOpt: unable to opt direct call 0x0000 at 0x04 in Lde/sizuag/android/database/UploadImage;.saveInstances
09-09 22:37:50.341: D/AndroidRuntime(25990): Shutting down VM
09-09 22:37:50.341: W/dalvikvm(25990): threadid=1: thread exiting with uncaught exception (group=0x410e02a0)
09-09 22:37:50.431: E/AndroidRuntime(25990): FATAL EXCEPTION: main
09-09 22:37:50.431: E/AndroidRuntime(25990): java.lang.NoClassDefFoundError: Decoder/BASE64Encoder
09-09 22:37:50.431: E/AndroidRuntime(25990):    at de.sizuag.android.database.UploadImage.saveInstances(UploadImage.java:50)
09-09 22:37:50.431: E/AndroidRuntime(25990):    at de.sizuag.android.database.UploadImage.<init>(UploadImage.java:35)
09-09 22:37:50.431: E/AndroidRuntime(25990):    at de.sizuag.android.staff.extensions.NewProblem$3.onPictureTaken(NewProblem.java:129)
09-09 22:37:50.431: E/AndroidRuntime(25990):    at android.hardware.Camera$EventHandler.handleMessage(Camera.java:823)
09-09 22:37:50.431: E/AndroidRuntime(25990):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-09 22:37:50.431: E/AndroidRuntime(25990):    at android.os.Looper.loop(Looper.java:137)
09-09 22:37:50.431: E/AndroidRuntime(25990):    at android.app.ActivityThread.main(ActivityThread.java:4921)
09-09 22:37:50.431: E/AndroidRuntime(25990):    at java.lang.reflect.Method.invokeNative(Native Method)
09-09 22:37:50.431: E/AndroidRuntime(25990):    at java.lang.reflect.Method.invoke(Method.java:511)
09-09 22:37:50.431: E/AndroidRuntime(25990):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1027)
09-09 22:37:50.431: E/AndroidRuntime(25990):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:794)
09-09 22:37:50.431: E/AndroidRuntime(25990):    at dalvik.system.NativeStart.main(Native Method)
09-09 22:37:50.431: E/AndroidRuntime(25990): Caused by: java.lang.ClassNotFoundException: Decoder.BASE64Encoder
09-09 22:37:50.431: E/AndroidRuntime(25990):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
09-09 22:37:50.431: E/AndroidRuntime(25990):    at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
09-09 22:37:50.431: E/AndroidRuntime(25990):    at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
09-09 22:37:50.431: E/AndroidRuntime(25990):    ... 12 more

1 个答案:

答案 0 :(得分:0)

尝试使用:

String imageString = android.util.Base64.encodeToString(data, Base64.DEFAULT);