· 8 years ago · Aug 22, 2018, 02:26 PM
1Preloaded database corruption issue in Android application
2HttpURLConnection conexion = (HttpURLConnection) url.openConnection();
3if(filePath.exists() && filePath.length() > 10000.00)
4{
5 downloaded = (int) filePath.length();
6 conexion.setRequestProperty("Range", "bytes=" + (filePath.length()) + "-");
7}
8else
9 conexion.setRequestProperty("Range", "bytes=" + downloaded + "-");
10
11conexion.setDoInput(true);
12conexion.setDoOutput(true);
13conexion.setUseCaches(false);
14conexion.connect();
15
16try {
17 totalFileLength = lengthOfFile + downloaded;
18 progressDialog.setMax(lengthOfFile + downloaded);
19 // downlod the file
20 input = new BufferedInputStream(conexion.getInputStream());
21 output = (downloaded==0)? new FileOutputStream(filePath): new FileOutputStream(filePath,true);
22 bout = new BufferedOutputStream(output, 1024);
23
24 byte data[] = new byte[1024];
25
26 while ((count = input.read(data, 0, 1024)) >= 0 && running) {
27 downloaded += count;
28 // publishing the progress....
29 //onProgressUpdate((int)(downloaded*100/lengthOfFile));
30 progressDialog.setProgress(downloaded);
31 bout.write(data, 0, count);
32 }
33} catch (Exception e) {
34 ...
35} finally {
36 try {
37 input.close();
38 bout.flush();
39 bout.close();
40 } catch(IOException e) {
41 ...
42 }
43}
44
45try {
46 myDbHelper.myDataBase.execSQL("CREATE TABLE IF NOT EXISTS FAVORITES (_id integer primary key autoincrement, MushroomID INTEGER)");
47 success = true;
48} catch (SQLException sqle) {
49 throw sqle;
50}
51
52java.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)
53 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
54 at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
55 at android.app.ActivityThread.access$1500(ActivityThread.java:117)
56 at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
57 at android.os.Handler.dispatchMessage(Handler.java:99)
58 at android.os.Looper.loop(Looper.java:130)
59 at android.app.ActivityThread.main(ActivityThread.java:3691)
60 at java.lang.reflect.Method.invokeNative(Native Method)
61 at java.lang.reflect.Method.invoke(Method.java:507)
62 at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
63 at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
64 at dalvik.system.NativeStart.main(Native Method)
65Caused by: android.database.sqlite.SQLiteDatabaseCorruptException: database disk image is malformed: CREATE TABLE IF NOT EXISTS FAVORITES (_id integer primary key autoincrement, MushroomID INTEGER)
66 at android.database.sqlite.SQLiteDatabase.native_execSQL(Native Method)
67 at android.database.sqlite.SQLiteDatabase.execSQL(SQLiteDatabase.java:1904)
68 at net.daleroy.fungifieldguide.services.MushroomService.MakeFavoriteTable(MushroomService.java:118)
69 at net.daleroy.fungifieldguide.services.MushroomService.OpenDB(MushroomService.java:64)
70 at net.daleroy.fungifieldguide.activities.FungiFieldGuide.onCreate(FungiFieldGuide.java:73)
71 at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
72 at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
73
74while ((count = input.read(data, 0, 1024)) >= 0 && running) {
75 downloaded += count;
76 progressDialog.setProgress(downloaded);
77 bout.write(data, 0, count);
78}
79bout.flush();
80bout.close();