-3

描画した画像を保存したいのですが、失敗が常に報告されます。

09-12 07:30:34.346: E / Panel (8003): IOEception
09-12 07:30:34.346: E / Panel (8003): java.io.IOException: Parent directory of file does not exist: / sdcard/anppp/2012Sep1273034.png
09-12 07:30:34.346: E / Panel (8003): at java.io.File.createNewFile (File.java: 1263)
09-12 07:30:34.346: E / Panel (8003): at aa.bb.cc.Panel.saveapp (Panel.java: 67)
09-12 07:30:34.346: E / Panel (8003): at aa.bb.cc.AndroidPaint.onOptionsItemSelected (AndroidPaint.java: 94)
09-12 07:30:34.346: E / Panel (8003): at android.app.Activity.onMenuItemSelected (Activity.java: 2170)
09-12 07:30:34.346: E / Panel (8003): at com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected (PhoneWindow.java: 730)
09-12 07:30:34.346: E / Panel (8003): at com.android.internal.view.menu.MenuItemImpl.invoke (MenuItemImpl.java: 139)
09-12 07:30:34.346: E / Panel (8003): at com.android.internal.view.menu.MenuBuilder.performItemAction (MenuBuilder.java: 855)
09-12 07:30:34.346: E / Panel (8003): at com.android.internal.view.menu.ExpandedMenuView.invokeItem (ExpandedMenuView.java: 89)
09-12 07:30:34.346: E / Panel (8003): at com.android.internal.view.menu.ExpandedMenuView.onItemClick (ExpandedMenuView.java: 93)
09-12 07:30:34.346: E / Panel (8003): at android.widget.AdapterView.performItemClick (AdapterView.java: 284)
09-12 07:30:34.346: E / Panel (8003): at android.widget.ListView.performItemClick (ListView.java: 3285)
09-12 07:30:34.346: E / Panel (8003): at android.widget.AbsListView $ PerformClick.run (AbsListView.java: 1640)
09-12 07:30:34.346: E / Panel (8003): at android.os.Handler.handleCallback (Handler.java: 587)
09-12 07:30:34.346: E / Panel (8003): at android.os.Handler.dispatchMessage (Handler.java: 92)
09-12 07:30:34.346: E / Panel (8003): at android.os.Looper.loop (Looper.java: 123)
09-12 07:30:34.346: E / Panel (8003): at android.app.ActivityThread.main (ActivityThread.java: 4363)
09-12 07:30:34.346: E / Panel (8003): at java.lang.reflect.Method.invokeNative (Native Method)
09-12 07:30:34.346: E / Panel (8003): at java.lang.reflect.Method.invoke (Method.java: 521)
09-12 07:30:34.346: E / Panel (8003): at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java: 860)
09-12 07:30:34.346: E / Panel (8003): at com.android.internal.os.ZygoteInit.main (ZygoteInit.java: 618)
09-12 07:30:34.346: E / Panel (8003): at dalvik.system.NativeStart.main (Native Method)

私のコード:

private Bitmap mBitmap;
private Canvas mCanvas;
private Bitmap tmpBitmap;
private Canvas tmpCanvas;
private DrawHandler mDrawHandler;
private Canvas tCanvas;
private String mImagePath = Environment.getExternalStorageDirectory() + "/anppp";
private File file;

public void saveapp() {

    Calendar currentDate = Calendar.getInstance();
    SimpleDateFormat formatter= new SimpleDateFormat("yyyyMMMddHmmss");
    String dateNow = formatter.format(currentDate.getTime());
    file = new File(mImagePath + "/" + dateNow +".png");
    FileOutputStream fos;
    try {
        file.createNewFile();
        fos = new FileOutputStream(file);
        tmpBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
        fos.close();
        } catch (FileNotFoundException e) {
        Log.e("Panel", "FileNotFoundException", e);
    }
    catch (IOException e) {
        Log.e("Panel", "IOEception", e);
    }
}

それだけです..何が間違っているのかわかりません;(

4

1 に答える 1

1

SDカードにanpppという名前のフォルダがないようです。だから私はあなたが最初にそれを使用してそれを作成することをお勧めします

File dirPath = new File(Environment.getExternalStorageDirectory().toString() + "/anppp");
dirPath.mkdirs();

そして今あなたがしているタスクを実行します。これがお役に立てば幸いです

于 2012-09-15T15:44:14.900 に答える