片段类中未定义的openOrCreateDatabase() [英] openOrCreateDatabase() undefined in the fragment class
本文介绍了片段类中未定义的openOrCreateDatabase()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个代码,其中在活动中放置了一个片段。现在在fragment类的OnCreate()函数中,以下代码中没有错误
I am writing a code in which I place an fragment within an activity. Now in the OnCreate() function of the fragment class, I am not having error in the following code
public class HomePage_Fragment extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SQLiteDatabase db = openOrCreateDatabase("DATABASE",android.content.Context.MODE_PRIVATE ,null);
}
@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container, Bundle savedInstance){
return inflater.inflate(R.layout.fragment_home_page,container,false);
}
}
错误:对于类型HomePage_Fragment
ERROR:The method openOrCreateDatabase(String, int, null) is undefined for the type HomePage_Fragment
代码非常简单,我已经使用过多次使用相同的命令,因此我确定语法是正确的。
The code is very simple and I have used the same commands many times, so I am sure the syntax is correct.
预先感谢
推荐答案
openOrCreateDatabase(名称,模式,工厂)
方法位于上下文类
更改此行
SQLiteDatabase db = openOrCreateDatabase("DATABASE",android.content.Context.MODE_PRIVATE ,null);
进入
SQLiteDatabase db = getActivity().openOrCreateDatabase("DATABASE",android.content.Context.MODE_PRIVATE ,null);
这篇关于片段类中未定义的openOrCreateDatabase()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文