Sign up ×
Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them, it only takes a minute:

I'm having trouble opening a Database.I can get the DB to open and close and grab the data that I require in a Layout class and push it to a UI fine. But i also want to open the DB in the background and read the data as well(Not at the same time as the UI). I am having trouble doing this and get a error in the Helperclass I am calling the class like this:

GenerateFiringData GenData=new GenerateFiringData(); //Generate the firing data 

and this is the class

    import android.app.Activity;
    import android.database.Cursor;
    import android.util.Log;


    public class GenerateFiringData extends Activity{
DBAdapter myDb1;

public GenerateFiringData(){
    openDB();  //open database
    ..... 

}   

private void openDB() {
    myDb1 = new DBAdapter(this);
    myDb1.open();// <<<<<<<<<<problem starts here
}

private void closeDB() {
    myDb1.close();
}
    }

When the 'myDb1.open()' code is called it is sent to

   // Open the database connection.
public DBAdapter open() {
    db = myDBHelper.getWritableDatabase();<<<---------errors here
    return this;
}

What am i doing wrong??? the database code for the UI part of my project goes thew this fine and i cant figure out why

Thanks Snow

share|improve this question
    
have You initialized Your databaseHelper myDBHelper ? – Opiatefuchs Jul 17 '13 at 22:25
    
This is called by the 'myDb1 = new DBAdapter(this);' public DBAdapter(Context ctx) { this.context = ctx; myDBHelper = new DatabaseHelper(context); is this what you mean... I'm a bit of a Green Horn at this Android stuff – Snowie Jul 18 '13 at 11:47

1 Answer 1

Found a work around Call the class as an intent like similar to a opening a new layout. Now sure if this is the 'Correct way" but it works

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.