getWritableDatabase()上的NullPointerException

时间:2012-08-10 07:44:24

标签: android getwritabledatabase

我在getWritableDatabase()

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

有一个实现不起作用“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

我意识到,我忘了初始化onCreate感谢大家

2 个答案:

答案 0 :(得分:3)

最有可能是您的Context

openHelper = new OpenHelper(context);

为空。确保已设置Context。但我建议你提供更多细节,在这里添加你的logcat。

答案 1 :(得分:0)

问题不在您的数据库类中,而在DatabaseTable.onCreate()..... java:27

请检查出来。

谢谢,

HAPS。