Hi all, I'm new to Android, however I am experienced with C# and Java. I have never had problems opening or communicating with a database until now. Every time I try to open/create a database using SQLiteOpenHelper's built-in getReadableDatabase or getWritableDatabase functions my program crashes with a NullPointerException. Here is the relevant code:
My SQLiteOpenHelper class: ------------------------------------------- public class SQLHelper extends SQLiteOpenHelper{ public SQLHelper(Context context, String db_name) { super(context, db_name, null, 1); } public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){} public void onCreate(SQLiteDatabase db){} public void onOpen(SQLiteDatabase db){} } -------------------------------------------- My main Activity class: ---------------------------------------------- public class BlackBook extends Activity{ private SQLHelper dbHelper; private SQLiteDatabase db; private ListProvider lp; private TextView tv; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); tv = (TextView) findViewById(R.id.errorText); lp = new ListProvider(); tv.setText(lp.Initiate()); } public class ListProvider extends ContentProvider { /* All mandatory, unmodified overrides here. Cut out for clarity of this discussion. */ public String Initiate() { dbHelper = new SQLHelper(getContext(), "LBB_DB.db"); try{ db = dbHelper.getReadableDatabase(); }catch (Exception e) {return e.toString();} finally{} return "Success!"; } } ---------------------------------------------- As you can see, I create a new ContentProvider class in order to obtain a Context() to pass to the SQLiteOpenHelper. This is what I saw in the NotePadProvider example, so please let me know if I've done this wrong and it is causing this error. This line does not throw an error: dbHelper = new SQLHelper(getContext(), "LBB_DB.db"); But the very next line throws a NullPointerException error: db = dbHelper.getReadableDatabase(); I have tried both getReadable and getWritable with no difference. I've been pulling my hair out over this one for well over five hours now, I would greatly appreciate some help pinpointing the source of the error if possible. Thanks for reading. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to android-beginners@googlegroups.com To unsubscribe from this group, send email to android-beginners-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---