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

  • Home
  • SEARCH
  • 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 9116663
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:43:44+00:00 2026-06-17T04:43:44+00:00

I’m downloading a database from a website. The downloaded database is called db.php and

  • 0

I’m downloading a database from a website. The downloaded database is called db.php
and it’s going to be stored at data/data/my.package.name/files under the name FishingMatey.db. The database is in the filesystem from the DDMS and I can open it on the PC in SQLite Studio. There my database is filled with the right tables and the right data. Here’s my code to download the SQLite database:

public boolean downloadDatabase() {
    try {
        // Log.d(TAG, "downloading database");
        URL url = new URL("http://myurl.com/db.php");

        // Open a connection to that URL */
        URLConnection ucon = url.openConnection();

        // Define InputStreams to read from the URLConnection
        InputStream is = ucon.getInputStream();
        BufferedInputStream bis = new BufferedInputStream(is);

        // Read bytes to the Buffer until there is nothing more to read(-1)
        ByteArrayBuffer baf = new ByteArrayBuffer(50);
        int current = 0;
        while ((current = bis.read()) != -1) {
            baf.append((byte) current);
        }

        // Convert the Bytes read to a String
        FileOutputStream fos = null;
        // Select storage location
        fos = this.context.openFileOutput(DATABASE_NAME, Context.MODE_PRIVATE);

        fos.write(baf.toByteArray());
        fos.close();
    } catch (IOException e) {
        Log.e("downloadDatabase", "downloadDatabase Error: ", e);
        return false;
    } catch (NullPointerException e) {
        Log.e("downloadDatabase", "downloadDatabase Error: ", e);
        return false;
    } catch (Exception e) {
        Log.e("downloadDatabase", "downloadDatabase Error: ", e);
        return false;
    }
    return true;
}

My problem: I can open the database with
SQLiteDatabase db = SQLiteDatabase.openDatabase("/data/data/com.example.menuswitcher/files/" + DATABASE_NAME, null, SQLiteDatabase.OPEN_READONLY);, but if I enter db.query(DATABASE_TABLE_Bewirtschafter, null, null, null, null, null, null); I receive the following error:

01-08 19:52:22.366: E/AndroidRuntime(6157): FATAL EXCEPTION: main
01-08 19:52:22.366: E/AndroidRuntime(6157): android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1

Here’s how I call it in the Activity:
this.b3.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {
            // TODO Auto-generated method stub
            DBAccess dbAccess = new DBAccess(HauptmenueActivity.this, 1, "FishingMatey.db");
            if (dbAccess.downloadDatabase()) {
                dbAccess.initDatabase();
                Cursor cur = dbAccess.createBewirtschafterAllCursor();
                Log.v("b3", cur.getString(cur.getColumnIndex("name")));
            } else {
                Log.e("b3", "Error!");
            }
        }
    });

Does anybody know why this doesn’t work?

  • 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-06-17T04:43:45+00:00Added an answer on June 17, 2026 at 4:43 am
    android.database.CursorIndexOutOfBoundsException: Index -1 requested, with a size of 1
    

    This error means that you forgot to call cursor.moveToFirst() before trying to read your Cursor.

    Cursor cursor = db.query(DATABASE_TABLE_Bewirtschafter, null, null, null, null, null, null);
    if(cursor.moveToFirst()) {
        // Do something with the first row, if it exists
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a view passing on information from a database: def serve_article(request, id): served_article
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am using jsonparser to parse data and images obtained from json response. When
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,

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.