1

以下代码似乎在 API 级别 11 及更高版本上运行良好:

   private ZipInputStream getFileFromZip(InputStream zipFileStream) throws FileNotFoundException, IOException {
     ZipInputStream zis = new ZipInputStream(zipFileStream);
     ZipEntry ze = null;
     while ((ze = zis.getNextEntry()) != null) {
       Log.w(ACTIVITY_LOG_TAG, "extracting file: '" + ze.getName() + "'...");
       return zis;
     }
     return null;
    }

但是在运行时抛出一个IOException错误,例如 10 或 8。我想在我的应用程序中也支持这些 API,所以我需要把它带到工作中......

我检查了所有文件名、路径等。再一次,在 3.0 下它可以工作。我也在使用 actionbarsherlock,尽管这不会影响 zip 输入流。

有人有什么想法吗???

更新

我忘了提到我正在使用AsyncTask<Void, Void, Void>.

Blackbelt 要求的 LogCat:

06-08 11:12:17.478: E/AndroidRuntime(405): FATAL EXCEPTION: AsyncTask #1
06-08 11:12:17.478: E/AndroidRuntime(405): java.lang.RuntimeException: An error occured while executing doInBackground()
06-08 11:12:17.478: E/AndroidRuntime(405):  at android.os.AsyncTask$3.done(AsyncTask.java:200)
06-08 11:12:17.478: E/AndroidRuntime(405):  at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:273)
06-08 11:12:17.478: E/AndroidRuntime(405):  at java.util.concurrent.FutureTask.setException(FutureTask.java:124)
06-08 11:12:17.478: E/AndroidRuntime(405):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:307)
06-08 11:12:17.478: E/AndroidRuntime(405):  at java.util.concurrent.FutureTask.run(FutureTask.java:137)
06-08 11:12:17.478: E/AndroidRuntime(405):  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1068)
06-08 11:12:17.478: E/AndroidRuntime(405):  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:561)
06-08 11:12:17.478: E/AndroidRuntime(405):  at java.lang.Thread.run(Thread.java:1096)
06-08 11:12:17.478: E/AndroidRuntime(405): Caused by: android.database.sqlite.SQLiteException: Unable to extract databases/RGBColortype.zip to data directory
06-08 11:12:17.478: E/AndroidRuntime(405):  at android.content.res.AssetManager.readAsset(Native Method)
06-08 11:12:17.478: E/AndroidRuntime(405):  at android.content.res.AssetManager.access$700(AssetManager.java:36)
06-08 11:12:17.478: E/AndroidRuntime(405):  at android.content.res.AssetManager$AssetInputStream.read(AssetManager.java:574)
06-08 11:12:17.478: E/AndroidRuntime(405):  at java.io.PushbackInputStream.read(PushbackInputStream.java:198)
06-08 11:12:17.478: E/AndroidRuntime(405):  at java.util.zip.ZipInputStream.getNextEntry(ZipInputStream.java:212)
06-08 11:12:17.478: E/AndroidRuntime(405):  at com.coloruapp.MainActivity.getFileFromZip(MainActivity.java:346)
06-08 11:12:17.478: E/AndroidRuntime(405):  at com.coloruapp.MainActivity.copyDatabaseFromAssets(MainActivity.java:321)
06-08 11:12:17.478: E/AndroidRuntime(405):  at com.coloruapp.MainActivity.access$2(MainActivity.java:315)
06-08 11:12:17.478: E/AndroidRuntime(405):  at com.coloruapp.MainActivity$DBInstaller.doInBackground(MainActivity.java:294)
06-08 11:12:17.478: E/AndroidRuntime(405):  at com.coloruapp.MainActivity$DBInstaller.doInBackground(MainActivity.java:1)
06-08 11:12:17.478: E/AndroidRuntime(405):  at android.os.AsyncTask$2.call(AsyncTask.java:185)
06-08 11:12:17.478: E/AndroidRuntime(405):  at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
06-08 11:12:17.478: E/AndroidRuntime(405):  ... 4 more

之后,我显然泄露了ProgressDialog......

06-08 11:12:19.058: D/ActionBarSherlock(405): [dispatchStop]
06-08 11:12:19.138: E/WindowManager(405): Activity com.coloruapp.MainActivity has       leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@46090078 that was originally added here
06-08 11:12:19.138: E/WindowManager(405): android.view.WindowLeaked: Activity com.coloruapp.MainActivity has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@46090078 that was originally added here
06-08 11:12:19.138: E/WindowManager(405):   at android.view.ViewRoot.<init>   (ViewRoot.java:247)
06-08 11:12:19.138: E/WindowManager(405):   at  android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
06-08 11:12:19.138: E/WindowManager(405):   at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
06-08 11:12:19.138: E/WindowManager(405):   at android.view.Window$LocalWindowManager.addView(Window.java:424)
06-08 11:12:19.138: E/WindowManager(405):   at android.app.Dialog.show(Dialog.java:241)
06-08 11:12:19.138: E/WindowManager(405):   at     com.coloruapp.MainActivity$DBInstaller.onPreExecute(MainActivity.java:310)
06-08 11:12:19.138: E/WindowManager(405):   at android.os.AsyncTask.execute(AsyncTask.java:391)
06-08 11:12:19.138: E/WindowManager(405):   at com.coloruapp.MainActivity.onCreate(MainActivity.java:92)
06-08 11:12:19.138: E/WindowManager(405):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
06-08 11:12:19.138: E/WindowManager(405):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
06-08 11:12:19.138: E/WindowManager(405):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
06-08 11:12:19.138: E/WindowManager(405):   at android.app.ActivityThread.access$2300(ActivityThread.java:125)
06-08 11:12:19.138: E/WindowManager(405):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
06-08 11:12:19.138: E/WindowManager(405):   at android.os.Handler.dispatchMessage(Handler.java:99)
06-08 11:12:19.138: E/WindowManager(405):   at android.os.Looper.loop(Looper.java:123)
06-08 11:12:19.138: E/WindowManager(405):   at android.app.ActivityThread.main(ActivityThread.java:4627)
06-08 11:12:19.138: E/WindowManager(405):   at java.lang.reflect.Method.invokeNative(Native Method)
06-08 11:12:19.138: E/WindowManager(405):   at java.lang.reflect.Method.invoke(Method.java:521)
06-08 11:12:19.138: E/WindowManager(405):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-08 11:12:19.138: E/WindowManager(405):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-08 11:12:19.138: E/WindowManager(405):   at dalvik.system.NativeStart.main(Native Method)
4

0 回答 0