-1

SD カードにビットマップを保存するコードがありますが、単純な Null Pointer Exception エラーが発生します ...

String sdcardState = android.os.Environment.getExternalStorageState();      
    String destPath = null;
/////////////////////////////////////////////////////////////////////////////////////
int indexSepar=absoluteFilePathSource.lastIndexOf(File.separator);//THIS IS THE ERROR LINE
////////////////////////////////////////////////////////////////////////////////////
    int indexPoint=absoluteFilePathSource.lastIndexOf(".");
    if(indexPoint<=1)
        indexPoint=absoluteFilePathSource.length();
    String fileNameDest=absoluteFilePathSource.substring(indexSepar+1, indexPoint);

    fileNameDest+="_AMNET";
    if (sdcardState.contentEquals(android.os.Environment.MEDIA_MOUNTED))
        destPath = android.os.Environment.getExternalStorageDirectory()
                + File.separator + fileNameDest+".png";

    OutputStream fout = null;
    try {

        Log.v("Path", destPath);
        fout = new FileOutputStream(destPath);          
        destBitmap.compress(Bitmap.CompressFormat.PNG, 100, fout);
        if(!IS_ENCODE_IMAGE_CH)
            Media.insertImage(getContentResolver(),destPath, fileNameDest, "AMNET Encoded");
        result=Uri.parse("file://"+destPath);
        sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, result)); 
        fout.flush();
        fout.close();

    } catch (IOException e) {
        e.printStackTrace();
    }

    destBitmap.recycle();

これが私の丸太猫です:

06-01 13:20:52.239: E/AndroidRuntime(1340): FATAL EXCEPTION: Thread-112
06-01 13:20:52.239: E/AndroidRuntime(1340): java.lang.NullPointerException
06-01 13:20:52.239: E/AndroidRuntime(1340):     at ir.megadev.amnet.MainActivity.encode(MainActivity.java:844)
    06-01 13:20:52.239: E/AndroidRuntime(1340):     at ir.megadev.amnet.MainActivity.access$2(MainActivity.java:769)
    06-01 13:20:52.239: E/AndroidRuntime(1340):     at ir.megadev.amnet.MainActivity$10$1.run(MainActivity.java:430)
    06-01 13:20:52.239: E/AndroidRuntime(1340):     at java.lang.Thread.run(Thread.java:856)
4

1 に答える 1

3

absoluteFilePathSource無効です

于 2013-06-01T13:33:24.527 に答える