数据库构造函数中的返回类型
问题描述:
我正在创建数据库连接到SQL应用程序中的SQLite。 连接发生错误。因为我必须使登录部分。数据库构造函数中的返回类型
public class DatabaseConnection extends SQLiteOpenHelper {
private static final int DATABASE_VERSION = 1;
// Database Name
private static final String DATABASE_NAME = "App1";
// Contacts table name
private static final String TABLE_CONTACTS = "contacts";
// Contacts Table Columns names
private static final String KEY_ID = "id";
private static final String KEY_NAME = "name";
private static final String KEY_PH_NO = "phone_number";
public Connection(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
// Creating Tables
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_CONTACTS_TABLE = "CREATE TABLE " + TABLE_CONTACTS + "("
+ KEY_ID + " INTEGER PRIMARY KEY," + KEY_NAME + " TEXT,"
+ KEY_PH_NO + " TEXT" + ")";
db.execSQL(CREATE_CONTACTS_TABLE);
}
// Create tables again
onCreate(db);
}
}
这里是全班。
public Connection(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
这部分是给错误的。
如何解决它?
答
您的构造函数名称需要与Java类名称相匹配。你的班级是DatabaseConnection
。您的构造函数是Connection
。这些不一样。重命名一个匹配其他。
请编辑您的问题并发布整个Java类。我怀疑班级名称不是'Connection'。 – CommonsWare
我已经添加了全班 –