开发者社区> 问答> 正文

局部变量初始化的问题

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可能没有被初始化?可是我初始化了的呀,这个错误如何发生的呢?

展开
收起
a123456678 2016-07-18 14:16:21 1732 0
1 条回答
写回答
取消 提交回答
  • 在 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);   
    }
    2019-07-17 19:57:50
    赞同 1 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载