httpURLConnection conexion = (httpURLConnection) url.openConnection();if(filePath.exists() && filePath.length() > 10000.00){ downloaded = (int) filePath.length(); conexion.setRequestProperty("Range","bytes=" + (filePath.length()) + "-");}else conexion.setRequestProperty("Range","bytes=" + downloaded + "-");conexion.setDoinput(true);conexion.setDoOutput(true);conexion.setUseCaches(false);conexion.connect();
…
try { totalfileLength = lengthOffile + downloaded; progressDialog.setMax(lengthOffile + downloaded); // downlod the file input = new BufferedinputStream(conexion.getinputStream()); output = (downloaded==0)? new fileOutputStream(filePath): new fileOutputStream(filePath,true); bout = new bufferedoutputstream(output,1024); byte data[] = new byte[1024]; while ((count = input.read(data,1024)) >= 0 && running) { downloaded += count; // publishing the progress.... //onProgressUpdate((int)(downloaded*100/lengthOffile)); progressDialog.setProgress(downloaded); bout.write(data,count); }} catch (Exception e) { ...} finally { try { input.close(); bout.flush(); bout.close(); } catch(IOException e) { ... }}
完全下载文件后,我打开数据库并向其中添加一个表.
try { myDbHelper.myDataBase.execsql("CREATE table IF NOT EXISTS FAVORITES (_ID integer primary key autoincrement,MushroomID INTEGER)"); success = true;} catch (sqlException sqle) { throw sqle;}
现在,这个代码在我运行它的每个设备上运行得非常好,但我的几个用户在execsql行上得到了这个错误.好像它不是单独使用三星galaxy SII(没有投诉和随后的堆栈跟踪与任何其他手机的这个错误)但我不完全确定它只是这款手机.
java.lang.RuntimeException: Unable to start activity ComponentInfo{net.Daleroy.fungifIEldguIDe/net.Daleroy.fungifIEldguIDe.activitIEs.FungiFIEldGuIDe}: androID.database.sqlite.sqliteDatabaseCorruptException: database disk image is malformed: CREATE table IF NOT EXISTS FAVORITES (_ID integer primary key autoincrement,MushroomID INTEGER) at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:1651) at androID.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667) at androID.app.ActivityThread.access00(ActivityThread.java:117) at androID.app.ActivityThread$H.handleMessage(ActivityThread.java:935) at androID.os.Handler.dispatchMessage(Handler.java:99) at androID.os.Looper.loop(Looper.java:130) at androID.app.ActivityThread.main(ActivityThread.java:3691) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:507) at com.androID.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907) at com.androID.internal.os.ZygoteInit.main(ZygoteInit.java:665) at dalvik.system.NativeStart.main(Native Method)Caused by: androID.database.sqlite.sqliteDatabaseCorruptException: database disk image is malformed: CREATE table IF NOT EXISTS FAVORITES (_ID integer primary key autoincrement,MushroomID INTEGER) at androID.database.sqlite.sqliteDatabase.native_execsql(Native Method) at androID.database.sqlite.sqliteDatabase.execsql(sqliteDatabase.java:1904) at net.Daleroy.fungifIEldguIDe.services.MushroomService.MakeFavoritetable(MushroomService.java:118) at net.Daleroy.fungifIEldguIDe.services.MushroomService.OpenDB(MushroomService.java:64) at net.Daleroy.fungifIEldguIDe.activitIEs.FungiFIEldGuIDe.onCreate(FungiFIEldGuIDe.java:73) at androID.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047) at androID.app.ActivityThread.performlaunchActivity(ActivityThread.java:1615)
我收到了从具有sgs2的用户下载的数据库副本,并且该文件的校验和已关闭.当我用sqlite manager(firefox插件)打开时,我也看不到文件中的任何数据或数据结构.我让他直接下载数据库的副本并将其放在他的数据文件夹中,应用程序正常工作.所以问题出在下载过程中的某个地方.
解决方法 从API级别9(AndroID 2.3)开始,您可以使用DownloadManager
来处理长时间运行的http下载: The download manager is a system service that handles long-running
http downloads. ClIEnts may request that a URI be downloaded to a
particular destination file. The download manager will conduct the
download in the background,taking care of http interactions and
retrying downloads after failures or across connectivity changes and
system reboots.
以下是演示DownloadManager用法的示例项目:Android DownloadManager Example.
我想你甚至可以尝试将DownloadManager支持到以前的AndroID版本(如果你需要支持它们).它的源代码可以在这里找到:DownloadManager.java
总结以上是内存溢出为你收集整理的Android应用程序中预加载的数据库损坏问题全部内容,希望文章能够帮你解决Android应用程序中预加载的数据库损坏问题所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)