Android error: database disk image is malformed (code 11)

Source: Internet
Author: User

You need to download the database from the server when you use the call display and query functions,

However, after downloading, database disk image is malformed (code 11) is always reported)

At first, I thought the query statement was incorrect. Later I realized that the error was the same as that when I Parsed the package,

The download format is corrupted.

The solution follows the policy,

The code for narrowing down the array read each time is as follows:

Public class DownloadTask {/*** @ param path * @ param filePath storage path * @ param progressDialog progress bar * @ return * @ throws Exception */public static File getFile (String path, string filePath, ProgressDialog progressDialog) throws Exception {URL url = new URL (path); HttpURLConnection connection = (HttpURLConnection) url. openConnection (); connection. setConnectTimeout (2000); connection. setRequestMethod ("GET "); If (connection. getResponseCode () == 200) {int total = connection. getContentLength (); progressDialog. setMax (total); InputStream is = connection. getInputStream (); // get the socket input stream File = new file (filePath); FileOutputStream fos = new FileOutputStream (File ); // file output stream byte [] buffer = new byte [1024]; int len; int progress = 0; while (len = is. read (buffer ))! =-1) {fos. write (buffer); progress + = len; progressDialog. setProgress (progress);} fos. flush (); is. close (); fos. close (); connection. disconnect (); return file;} return null ;}

You can reduce the value of 1024 in this row to avoid damages,

 byte[] buffer = new byte[1024];  

Because it is always wrong, I even changed it

byte[] buffer = new byte[8];

This is correct, but there is a drawback: downloading is slow, and the downloading database is 16 MB, which is extremely slow,

Temporary solution.

Author: jason0539


Blog: (reprinted please explain the source)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.