1

そのため、メインフォルダー内のあるフォルダーから別のフォルダーにファイルを転送できるファイル転送アプリケーションを備えたアプリを構築しています。ただし、「VM では ... バイトを割り当てられません」というエラーが表示されます。

Logcat エラー:

04-16 16:32:06.072: E/dalvikvm-heap(17644): 184440-byte external allocation too large for this process.
04-16 16:32:06.132: E/GraphicsJNI(17644): VM won't let us allocate 184440 bytes

誰かがこれを克服する解決策を持っていますか? ファイルではなく画像に関する投稿をいくつか見ました。

コードの追加: (要求どおり)。このコードは他の場所にもコピーされていることに注意してください。ただし、私が独自に行った変更がいくつかあります。

private static void copyFile(File sourceFile, File destFile)
            throws IOException {
    if (!sourceFile.exists()) {
            return;
    }
    if (!destFile.exists()) {
            destFile.createNewFile();
    }
    destFile = new File(destFile.toString().substring(0, destFile.toString().lastIndexOf('/')));
    FileChannel source = null;
    FileChannel destination = null;
    source = new FileInputStream(sourceFile).getChannel();
    destination = new FileOutputStream(destFile).getChannel();
    if (destination != null && source != null) {
            destination.transferFrom(source, 0, source.size());
    }
    if (source != null) {
            source.close();
    }
    if (destination != null) {
            destination.close();
        }
    }

人々が言及しているように、メモリエラーはイメージであり、私の厄介なバグを見つけてくれてありがとう. このfileNotFoundExceptionを終了したらすぐに修正します。

logcat が更新されるのを長く待って申し訳ありませんが、copy file メソッド内に try と catch を追加するのを忘れていました。別のメソッドが別のメソッドから別のエラーをキャッチし、その上にあったものを表示しました。

04-16 18:19:41.322: W/System.err(4989): java.io.FileNotFoundException: /mnt/sdcard/ActivityApp (Is a directory)
04-16 18:19:41.322: W/System.err(4989):     at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
04-16 18:19:41.322: W/System.err(4989):     at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
04-16 18:19:41.322: W/System.err(4989):     at java.io.FileOutputStream.<init>(FileOutputStream.java:94)
04-16 18:19:41.322: W/System.err(4989):     at java.io.FileOutputStream.<init>(FileOutputStream.java:66)
04-16 18:19:41.322: W/System.err(4989):     at tab.layout.FileFusionActivity.copyFile(FileFusionActivity.java:107)
04-16 18:19:41.322: W/System.err(4989):     at tab.layout.FileFusionActivity.onListItemClick(FileFusionActivity.java:78)
04-16 18:19:41.322: W/System.err(4989):     at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
04-16 18:19:41.322: W/System.err(4989):     at android.widget.AdapterView.performItemClick(AdapterView.java:284)
04-16 18:19:41.322: W/System.err(4989):     at android.widget.ListView.performItemClick(ListView.java:3513)
04-16 18:19:41.322: W/System.err(4989):     at android.widget.AbsListView$PerformClick.run(AbsListView.java:1812)
04-16 18:19:41.322: W/System.err(4989):     at android.os.Handler.handleCallback(Handler.java:587)
04-16 18:19:41.322: W/System.err(4989):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-16 18:19:41.322: W/System.err(4989):     at android.os.Looper.loop(Looper.java:123)
04-16 18:19:41.322: W/System.err(4989):     at android.app.ActivityThread.main(ActivityThread.java:3683)
04-16 18:19:41.322: W/System.err(4989):     at java.lang.reflect.Method.invokeNative(Native Method)
04-16 18:19:41.322: W/System.err(4989):     at java.lang.reflect.Method.invoke(Method.java:507)
04-16 18:19:41.322: W/System.err(4989):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
04-16 18:19:41.332: W/System.err(4989):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
04-16 18:19:41.332: W/System.err(4989):     at dalvik.system.NativeStart.main(Native Method)
4

1 に答える 1

1

編集:以前に気づいたはずですが、丸太の猫がそれを証明しています。エラーはこの行にあります

destFile = new File(destFile.toString().substring(0, destFile.toString().lastIndexOf('/')));

このようなものに変更します

 destFile = new File(destFile.toString().substring(0, destFile.toString().lastIndexOf('/')),"hello.dat");

表示されているエラーは、コピー プロセスに直接関係していない可能性があります。メモリ使用量を確認するためにアプリをプロファイリングしましたか? あなたが試すことができる別のことは、この質問で概説されているように、ファイルをチャンクでコピーすることです

于 2012-04-16T18:16:06.473 に答える