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 6223423
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:29:17+00:00 2026-05-24T08:29:17+00:00

I am (re)writing an android app that uses an SQLite database to store various

  • 0

I am (re)writing an android app that uses an SQLite database to store various items, at the moment I am trying to open the database but I get the following logcat error:

08-04 13:05:52.735: ERROR/AndroidRuntime(7793):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1651)
08-04 13:05:52.735: ERROR/AndroidRuntime(7793):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
08-04 13:05:52.735: ERROR/AndroidRuntime(7793):     at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-04 13:05:52.735: ERROR/AndroidRuntime(7793):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
08-04 13:05:52.735: ERROR/AndroidRuntime(7793):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-04 13:05:52.735: ERROR/AndroidRuntime(7793):     at android.os.Looper.loop(Looper.java:123)
08-04 13:05:52.735: ERROR/AndroidRuntime(7793):     at android.app.ActivityThread.main(ActivityThread.java:3691)
08-04 13:05:52.735: ERROR/AndroidRuntime(7793):     at java.lang.reflect.Method.invokeNative(Native Method)
08-04 13:05:52.735: ERROR/AndroidRuntime(7793):     at java.lang.reflect.Method.invoke(Method.java:507)
08-04 13:05:52.735: ERROR/AndroidRuntime(7793):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
08-04 13:05:52.735: ERROR/AndroidRuntime(7793):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
08-04 13:05:52.735: ERROR/AndroidRuntime(7793):     at dalvik.system.NativeStart.main(Native Method)
08-04 13:05:52.735: ERROR/AndroidRuntime(7793): Caused by: android.database.sqlite.SQLiteException: unable to open database file
08-04 13:05:52.735: ERROR/AndroidRuntime(7793):     at android.database.sqlite.SQLiteDatabase.dbopen(Native Method)
08-04 13:05:52.735: ERROR/AndroidRuntime(7793):     at android.database.sqlite.SQLiteDatabase.<init>(SQLiteDatabase.java:1960)
08-04 13:05:52.735: ERROR/AndroidRuntime(7793):     at android.database.sqlite.SQLiteDatabase.openDatabase(SQLiteDatabase.java:887)
08-04 13:05:52.735: ERROR/AndroidRuntime(7793):     at myApps.ShoppingList.Database.openDatabase(Database.java:83)
08-04 13:05:52.735: ERROR/AndroidRuntime(7793):     at myApps.ShoppingList.RoomList.onCreate(RoomList.java:25)
08-04 13:05:52.735: ERROR/AndroidRuntime(7793):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
08-04 13:05:52.735: ERROR/AndroidRuntime(7793):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)
08-04 13:05:52.735: ERROR/AndroidRuntime(7793):     ... 11 more

The code I have at the moment is pretty incomplete, I am just adding bits and pieces to it and trying to get them to run properly until the errors that I get are to do with missing code. (making sure that the code I have in the app works before I add in loads of code and get lost)

I have checked that I am accessing the correct path and that the database name is correct, I have also tried to get the new app to open the old database file (which still works in the old app) but I get the same logcat errors, so I’m lead to believe that it is something to do with some other code. I’m really not sure where to go from here. If you need any more info or code I will post it up at request. Thanks for any help you guys can give 🙂

Here are the two classes that are causing the problem atm:

This is the list class, it will eventually be a list of all items in the database with a checkbox at the right hand side of the list item, when checked it will remove the item from the list and put it on a different list (not important at the moment)

public class RoomList extends ListActivity{
public String Room = MainMenu.room;
protected Database listdb;
MyAdapter adapterList;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.room);

    listdb = new Database(this, Room, null, 0);
    listdb.openDatabase();

    fillList();
}

private void fillList(){
    Cursor cursor = null;
    cursor = listdb.getRoom(Room);

    //not entirely sure how the managing cursor works, i think it just keeps everything synchronised
    startManagingCursor(cursor);

    //takes string values from the database, will eventually be displayed in the list views
    String [] names = new String []{Database.KEY_NAME, Database.KEY_SIZE, Database.KEY_BRAND, Database.KEY_TYPE, Database.KEY_DESCRIPTION};

    //sets what xml variables get modified with the taken strings
    int [] holder = new int []{R.id.additem, R.id.listDescription};

    //again not entirely sure how this method works, from what i can gather it basically defines which
    //layout to access when filing the xml variables in "holder" with the strings in "names"
    adapterList = new MyAdapter(RoomList.this, cursor);

            //seems to send whatever changes made with the last line of 
    //code to become a ListAdapter in order to be displayed as a list
}

private class MyAdapter extends ResourceCursorAdapter {

    public MyAdapter(Context context, Cursor cur) {
        super(context, R.layout.room, cur);
    }

    @Override
    public View newView(Context context, Cursor cur, ViewGroup parent) {
        LayoutInflater li = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        return li.inflate(R.layout.room, parent, false);
    }

    @Override
    public void bindView(View view, Context context, Cursor cur) {
        TextView tvListText = (TextView)view.findViewById(R.id.listButton);
        CheckBox cbListCheck = (CheckBox)view.findViewById(R.id.checkbox1);

        tvListText.setText(cur.getString(cur.getColumnIndex(listdb.KEY_NAME)));
        cbListCheck.setChecked((cur.getInt(cur.getColumnIndex(listdb.KEY_ONLIST))==0? false:true));
    }
}
}

here is the class that accesses the database:

public class Database extends SQLiteOpenHelper{

private static final String DATABASE_DIRECTORY = "data/data/myApps.ShoppingList/database/";
private static final String DATABASE_NAME = "listdb.sqlite";
private static final String DATABASE_PATH = DATABASE_DIRECTORY + DATABASE_NAME;
private static final String DATABASE_ITEMS_TABLE = "items";
private static final String DATABASE_CATEGORY_TABLE = "categorys";
public static final String KEY_NAME = "name";
public static final String KEY_DESCRIPTION = "description";
public static final String KEY_BRAND = "brand";
public static final String KEY_SIZE = "size";
public static final String KEY_TYPE = "type";
public static final String KEY_ROOM = "room";
public static final String KEY_ONLIST = "onList";
public static final String KEY_ROWID = "_id";
static SQLiteDatabase listdb;
private Context m_context;

public Database(Context context, String name, CursorFactory factory, int version) {
    super(context, DATABASE_NAME, null, 1);
    m_context = context;
}

public void onCreate(SQLiteDatabase db) {}

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {}

public void createDatabase() throws IOException{
    boolean exists = checkDatabase();       
    if(!exists){
        this.getWritableDatabase();  
        try{
            copyDatabase();
        } catch(IOException e){
            throw new Error("Error copying database");
        }
    }
}

private boolean checkDatabase(){
    SQLiteDatabase check = null;        
    try{
        check = SQLiteDatabase.openDatabase(DATABASE_PATH, null, SQLiteDatabase.OPEN_READWRITE);
    } catch (SQLiteException e){}

    if(check != null){
        check.close();
        return true;
    }
    else return false;
}
private void copyDatabase() throws IOException{
    InputStream in = m_context.getAssets().open(DATABASE_NAME);
    OutputStream out = new FileOutputStream(DATABASE_PATH);
    byte[] buffer = new byte[1024];
    int length;

    while((length = in.read(buffer)) > 0){
        out.write(buffer, 0, length);
    }       
    out.flush();
    out.close();
    in.close();
}


public void openDatabase() throws SQLException{
    listdb = SQLiteDatabase.openDatabase(DATABASE_PATH, null, SQLiteDatabase.OPEN_READWRITE);
}

public synchronized void close(){
    if(listdb != null){
        listdb.close();
    }
    super.close();
}

public Cursor getRoom(String roomId){
    if (roomId=="1"){
        Cursor cursor = listdb.query(DATABASE_ITEMS_TABLE, new String[]{KEY_ROWID, KEY_NAME, KEY_BRAND, KEY_DESCRIPTION, KEY_SIZE, KEY_TYPE, KEY_ROOM, KEY_ONLIST},KEY_ROOM + " = 1 " + "AND " + KEY_ONLIST + " != 1 ", null, null, null, null, null);
        return cursor;
    }
    else if (roomId=="2"){
        Cursor cursor = listdb.query(DATABASE_ITEMS_TABLE, new String[]{KEY_ROWID, KEY_NAME, KEY_BRAND, KEY_DESCRIPTION, KEY_SIZE, KEY_TYPE, KEY_ROOM, KEY_ONLIST},KEY_ROOM + " = 2 " + "AND " + KEY_ONLIST + " != 1 ", null, null, null, null, null);
        return cursor;
    }
    else if (roomId=="3"){
        Cursor cursor = listdb.query(DATABASE_ITEMS_TABLE, new String[]{KEY_ROWID, KEY_NAME, KEY_BRAND, KEY_DESCRIPTION, KEY_SIZE, KEY_TYPE, KEY_ROOM, KEY_ONLIST},KEY_ROOM + " = 3 " + "AND " + KEY_ONLIST + " != 1 ", null, null, null, null, null);
        return cursor;
    }
    else if (roomId=="4"){
        Cursor cursor = listdb.query(DATABASE_ITEMS_TABLE, new String[]{KEY_ROWID, KEY_NAME, KEY_BRAND, KEY_DESCRIPTION, KEY_SIZE, KEY_TYPE, KEY_ROOM, KEY_ONLIST},KEY_ROOM + " = 4 " + "AND " + KEY_ONLIST + " != 1 ", null, null, null, null, null);
        return cursor;
    }
    else{
        Cursor cursor = listdb.query(DATABASE_ITEMS_TABLE, new String[]{KEY_ROWID, KEY_NAME, KEY_BRAND, KEY_DESCRIPTION, KEY_SIZE, KEY_TYPE, KEY_ROOM, KEY_ONLIST},KEY_ONLIST + "= 1" , null, null, null, null, null);
        return cursor;
    }
}
}
  • 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-24T08:29:18+00:00Added an answer on May 24, 2026 at 8:29 am

    Why are you using an SQLiteOpenHelper, instead of using SQLiteDatabase.open?
    And why are you hardcoding the database path?

    DATABASE_DIRECTORY = "data/data/myApps.ShoppingList/database/";
    

    On many devices I saw it’s actually …/databases/, but anyhow, use getDatabasePath to obtain it.

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

Sidebar

Related Questions

I am looking into writing an Android app that has a database of approximately
I'm writing an Android application that uses OpenGL ES (GLSurfaceView and GLSurfaceView.Renderer). The problem
I'm learning Java and writing an android app that consumes a JSON object that
I am writing a screen scraping app that reads out various pages and extracts
I'm writing an Android application that I want to be able to send requests
I'm writing an Android app where users can upload video to Youtube. I'd like
I am writing an android app. I want to pass some data across the
Writing a JSP page, what exactly does the <c:out> do? I've noticed that the
Writing my first Linq application, and I'm trying to find the best way to
I writing a report in Visual Studio that takes a user input parameter and

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.