K
K
kirchevsky2012-06-28 10:04:19
Android
kirchevsky, 2012-06-28 10:04:19

Accessing the database from AsyncTask - NullPointerException on GetDatabaseWritable How to fix?

So, I'm on to the community as always with stupid questions. Excuse me for often resorting to this method of solving my problems, but a cursory search in Google did not give certainty, although the description of this problem is quite common.

There is a class:

public  class  AddTTNActivity  extends  ListActivity  implements  OnGesturePerformedListener

In OnCreate of this class, we initialize our database:
        dbHelper =  new  NewPostDbAdapter ( this ) ;
        dbHelper. open ( ) ;

In the same class, we perform some manipulations with the base, but this is essentially not important ...
Next, we have the AsyncTask class, which exists separately:
public  class  DoBackgroundUpdate  extends  AsyncTask < Cursor,  Integer , Void >


How to access the database from AsyncTask with minimal problems?

P.S. Tried to do something like this:
public  NewPostDbAdapter open ( )  throws  SQLException  {
           try  {
dbHelper  =  new  NewPostDatabaseHelper ( context ) ;
database  =  dbHelper. getWritableDatabase ( ) ;
}
           catch  ( SQLiteException e )  {
close ( ) ;
dbHelper  =  new  NewPostDatabaseHelper ( context ) ;
database  =  dbHelper.getWritableDatabase ( ) ;     
                }
return  this ;
}
 

But the result did not work, I will be grateful for the help!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kirchevsky, 2012-06-28
@kirchevsky

Problem solved, sorry. :)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question