ZipInputStream.getNextEntry()在3.0以下的Android版本上抛出IOException(API11)

时间:2013-06-08 08:42:39

标签: android fileinputstream

以下代码似乎在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)

0 个答案:

没有答案