本文介绍了NullPointerException异常上getWritableDatabase()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对getWritableDatabase问题NullPointerException异常()

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);
            }
        }

有是一个实现不起作用openHelper.getWritableDatabase()

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);
                        }
                    }
                }

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

推荐答案

最有可能你的上下文

openHelper = new OpenHelper(context);

为空。请确保您的上下文设置。但我建议你提供更多的细节,在这里添加您的logcat的。

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

这篇关于NullPointerException异常上getWritableDatabase()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-03 12:51