我是按此教程做的:
http://www.ibm.com/developerworks/cn/opensource/os-cn-sqlite/index.htmlpublic void onCreate(Bundle savedInstanceState) {
SQLiteDatabase db=(new DatabaseHelper(getContext())).getWritableDatabase();
}public class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context, String name, CursorFactory cursorFactory, int version)
{
super(context, name, cursorFactory, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO 创建数据库后,对数据库的操作
}
} db=(new DatabaseHelper(getContext())).getWritableDatabase(); 这句总是出错(getContext部分),请问是为什么呢?
eclipse提示:The method getContext() is undefined for the type main_activity
http://www.ibm.com/developerworks/cn/opensource/os-cn-sqlite/index.htmlpublic void onCreate(Bundle savedInstanceState) {
SQLiteDatabase db=(new DatabaseHelper(getContext())).getWritableDatabase();
}public class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context, String name, CursorFactory cursorFactory, int version)
{
super(context, name, cursorFactory, version);
}
@Override
public void onCreate(SQLiteDatabase db) {
// TODO 创建数据库后,对数据库的操作
}
} db=(new DatabaseHelper(getContext())).getWritableDatabase(); 这句总是出错(getContext部分),请问是为什么呢?
eclipse提示:The method getContext() is undefined for the type main_activity
提示没这个方法、LZ用你那个类名.this替换试试、
{
super(context, name, cursorFactory, version);
}//new DatabaseHelper(this).getWritableDatabase(); //
"database_Name");
SQLiteDatabase db = DatabaseHelper.getWritableDatabase();
"database_Name");
SQLiteDatabase db = dbHelper.getWritableDatabase();