public class DatabaseHandler extends SQLiteOpenHelper {
// All Static variables
// Database Version
private static final int DATABASE_VERSION = 1;
// Database Name
private static final String DATABASE_NAME = "contextsManager";
// Locations table name
private static final String TABLE_LOCATIONLABLES = "locationLables";
// LOCATIONLABLES Table Columns names
private static final String KEY_LOCID = "loc_id";
private static final String KEY_LOCNAME = "loc_name";
public DatabaseHandler(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
String TABLE_LOCATIONLABLES = "CREATE TABLE " + TABLE_LOCATIONLABLES + "("
+ KEY_LOCID + " INTEGER PRIMARY KEY," + KEY_LOCNAME + " TEXT,"
+ ")";
db.execSQL(TABLE_LOCATIONLABLES);
}
提示说的是局部变量TABLE_LOCATIONLABLES可能没有被初始化?可是我初始化了的呀,这个错误如何发生的呢?
在 oncreate(db) 里重命名 字符串 TABLE_LOCATIONLABLES
@Override
public void onCreate(SQLiteDatabase db) {
String mQuery = "CREATE TABLE " + TABLE_LOCATIONLABLES + "("
+ KEY_LOCID + " INTEGER PRIMARY KEY," + KEY_LOCNAME + " TEXT,"
+ ")";
db.execSQL(mQuery);
}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。