将String Base64插入sqlite

时间:2014-01-27 03:19:03

标签: android sqlite base64

我是初学Android开发者,我需要你的帮助。我试图用base64从图像中获取字符串。当我想插入sqlite时。我收到了一个错误。这是我的base64代码:

private String photoToBase64String(String photopath) {
    long filelen = (new File(photopath).length()<<32)>>32;
    if (1048576 < filelen) {
        Log.e("imsmobilememory","Picture too big !");
        return "";
    }
    byte[] rawbytebuffer = new byte[(int)filelen];      
    StringBuilder sbp = new StringBuilder();
    try {
        BufferedInputStream bis = new BufferedInputStream(new FileInputStream(photopath));
        int res = bis.read(rawbytebuffer, 0, rawbytebuffer.length);
        bis.close();
        if (res == rawbytebuffer.length) {
            sbp.append(Base64.encodeToString(rawbytebuffer, Base64.DEFAULT|Base64.NO_WRAP));
        } else {
            Log.e("photoToB64Str","Error: Data read != bufferlength should not happen");
            return "";
        }           
    } catch (FileNotFoundException e) {
        Log.e("info","Photo not found !");
        return "";
    } catch (IOException ex) {
        Log.e("info","Error while reading file !");
        return "";
    } finally {

    }
    return sbp.toString();
}

这是我的错误logcat:

01-27 11:15:04.595:E / AndroidRuntime(6368):致命异乎寻常:主要 01-27 11:15:04.595:E / AndroidRuntime(6368):java.lang.NullPointerException 01-27 11:15:04.595:E / AndroidRuntime(6368):at java.io.File.fixSlashes(File.java:185) 01-27 11:15:04.595:E / AndroidRuntime(6368):at java.io.File。(File.java:134) 01-27 11:15:04.595:E / AndroidRuntime(6368):at ims.app.mobileorder.EntryTO.photoToBase64String(EntryTO.java:94) 01-27 11:15:04.595:E / AndroidRuntime(6368):at ims.app.mobileorder.EntryTO.access $ 7(EntryTO.java:93) 01-27 11:15:04.595:E / AndroidRuntime(6368):at ims.app.mobileorder.EntryTO $ 4.onClick(EntryTO.java:237) 01-27 11:15:04.595:E / AndroidRuntime(6368):在android.view.View.performClick(View.java:4380) 01-27 11:15:04.595:E / AndroidRuntime(6368):在android.view.View $ PerformClick.run(View.java:18094) 01-27 11:15:04.595:E / AndroidRuntime(6368):在android.os.Handler.handleCallback(Handler.java:725) 01-27 11:15:04.595:E / AndroidRuntime(6368):在android.os.Handler.dispatchMessage(Handler.java:92) 01-27 11:15:04.595:E / AndroidRuntime(6368):在android.os.Looper.loop(Looper.java:137) 01-27 11:15:04.595:E / AndroidRuntime(6368):在android.app.ActivityThread.main(ActivityThread.java:5279) 01-27 11:15:04.595:E / AndroidRuntime(6368):at java.lang.reflect.Method.invokeNative(Native Method) 01-27 11:15:04.595:E / AndroidRuntime(6368):at java.lang.reflect.Method.invoke(Method.java:511) 01-27 11:15:04.595:E / AndroidRuntime(6368):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:1102) 01-27 11:15:04.595:E / AndroidRuntime(6368):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 01-27 11:15:04.595:E / AndroidRuntime(6368):at dalvik.system.NativeStart.main(Native Method)

0 个答案:

没有答案