Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6682415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:42:12+00:00 2026-05-26T04:42:12+00:00

I have an android application that begins by downloading a large database to the

  • 0

I have an android application that begins by downloading a large database to the sdcard (a little over 50mb) in an asynctask. The download code is as follows.

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, 0, 1024)) >= 0 && running) {
        downloaded += count;
        // publishing the progress....
        //onProgressUpdate((int)(downloaded*100/lengthOfFile));
        progressDialog.setProgress(downloaded);
        bout.write(data, 0, count);
    }
} catch (Exception e) {
    ...
} finally {
    try {
        input.close();
        bout.flush();
        bout.close();
    } catch(IOException e) {
        ...
    }
}

After downloading the file completely I open the database and add a table to it.

try {
    myDbHelper.myDataBase.execSQL("CREATE TABLE IF NOT EXISTS FAVORITES (_id integer primary key autoincrement, MushroomID INTEGER)");
    success = true;
} catch (SQLException sqle) {
    throw sqle;
}

Now, this code works wonderfully on every device I run it on, but several of my users are getting this error on the execSQL line. It seems like it is not working on the Samsung Galaxy SII alone (there hasn’t been a complaint and subsequent stacktrace with this error with any other phone) but I’m not entirely sure its just this phone.

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.access$1500(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)

I’ve received a copy of the database downloaded from a user with a sgs2 and the checksum of the file is off. I also cannot see any data or data structure in the file when I open with sqlite manager (firefox plugin). I let him download a copy of the database directly and place it in his data folder and the application works fine. So the problem is somewhere in the download process.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:42:13+00:00Added an answer on May 26, 2026 at 4:42 am

    Starting from the API level 9 (Android 2.3) you can use DownloadManager to handle long-running HTTP downloads:

    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.

    Here is the example project which demonstrates DownloadManager usage: Android DownloadManager Example.

    I think you can even try to backport DownloadManager to the previous Android versions (if you need to support them). Its source code can be found here: DownloadManager.java

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have an android application that handles a sql-lite database and i need to
I have an Android Application that has four activities. None is very large and
I have an Android application that installs a database (~2000 rows across all tables)
I have an Android application that connects to Facebook to request authorization of an
I have a Web Service and an Android application that uses this web service.
I want to build an notepad-style application on android that will have syntax highlighting.
I want to integrate the zxing source code to my Android application. I have
I have an android application that starts an activity and is running well. I
I have an Android application that I've been working on, and it's implemented using
I have an Android application that is a TabHost with a WebView. I use

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.