Question

i have a problem NullPointerException on getWritableDatabase()

public class DatabaseTable extends Activity {
            private Context context;
            @Override
            public void onCreate(Bundle savedInstanceState) {
                LBD conection = LBD.get(this);
                super.onCreate(savedInstanceState);
            }
        }

There is an implementation does not work "openHelper.getWritableDatabase()"

       public class LBD {
                    private Context context;
                    private static SQLiteDatabase db;
                    private OpenHelper openHelper;
                    public static LBD get(Context context) {
                        LBD lbd = new LBD(context);
                        lbd.open();
                        return lbd;
                    }
                    public LBD(Context c) {
                        context = c;
                    }
                    final public void open() {
                                openHelper = new OpenHelper(context);
                                db = openHelper.getWritableDatabase();

                    }
                    public class OpenHelper extends SQLiteOpenHelper {
                        OpenHelper(Context context) {
                            super(context, "rss_base.db", null, 3);
                        }
                    }
                }

enter image description here

enter image description here

I realized, I forgot to initialize the onCreate Thanks to everyone

Was it helpful?

Solution

Most likely your Context

openHelper = new OpenHelper(context);

is null. Make sure that your Context is set. But i recommend to you provide more details, add here your logcat.

OTHER TIPS

Problem is not in your Database Class, its at DatabaseTable.onCreate()..... java:27

Please check it out.

Thanks,

Haps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top