我被困在我的代码上,一直在关注 Youtube 上的 newboston 教程。下面是我的代码,但由于某种原因,我遇到了错误,我无法弄清楚,有什么提示吗?
这是我的 RedemptionDB.java 类,在这段代码中就行
public RedemptionDB(Context c){
Context = c;
}
我收到一个错误,告诉我设置方法返回类型为 void,但在代码中,Bucky 没有那样做。
我得到的下一个错误是:
public RedmptionDB open(){
它告诉我:Creat Class RedemptionDB,它是我在代码开头想到的创建的!
package com.aloadofbs.redemptioncardmanager;
import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class RedemptionDB {
private static final String DB_NAME = "RedempDB";
private static final int DB_VERSION = 1;
private static final String TABLE = "cards";
public static final String KEY_ID = "_id"; // Special for id
public static final String KEY_CARDNUMBER = "card_number";
public static final String KEY_CARDNAME = "card_name";
public static final String KEY_BRIGCOLOR = "brig_color";
public static final String KEY_CARDPT = "power_toughness";
public static final String KEY_QTY = "qty";
public static final String KEY_VALUE = "value";
public static final String KEY_C = "C";
public static final String KEY_TYPE = "card_type";
public static final String KEY_SET = "card_set";
public static final String KEY_RARITY = "card_rarity";
public static final String KEY_VERSE = "card_verse";
public static final String KEY_IDENTIFIER = "card_identifiers";
public static final String KEY_ABILITIES = "card_special_ability";
private static DbHelper ourHelper;
private static Context ourContext;
private static SQLiteDatabase ourDatabase;
private static class DbHelper extends SQLiteOpenHelper{
public DbHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
// TODO Auto-generated constructor stub
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("CREATE TABLE" + TABLE + " ("+ KEY_ID + "INTEGER PRIMARY KEY ATOINCREMENT, " + KEY_CARDNUMBER + "TEXT NOT NULL, " + KEY_CARDNAME + "TEXT NOT NULL, " + KEY_BRIGCOLOR + "TEXT NOT NULL, " + KEY_CARDPT + "TEXT, " + KEY_QTY + "INTEGER, " + KEY_VALUE + "INTEGER, " + KEY_C + "TEXT, " + KEY_TYPE + "TEXT, " + KEY_SET + "TEXT, " + KEY_RARITY + "TEXT, " + KEY_VERSE + "TEXT NOT NULL, " + KEY_IDENTIFIER + "TEXT NOT NULL, " + KEY_ABILITIES + " TEXT NOT NULL);"
);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE);
onCreate(db);
}
public RedemptionDB (Context c){
Context = c;
}
public RedmptionDB open(){
ourHelper = new DbHelper(ourContext);
ourDatabase = ourHelper.getWritableDatabase();
return this;
}
public void close(){
ourHelper.close();
ourDatabase.close();
}
}
public long createEntry(String cardname, String cardset,
String cardcolor, String cardtype) {
// TODO Auto-generated method stub
ContentValues cv = new ContentValues();
cv.put(KEY_CARDNAME, cardname);
cv.put(KEY_BRIGCOLOR, cardcolor);
cv.put(KEY_TYPE, cardtype);
cv.put(KEY_SET, cardset);
return ourDatabase.insert(TABLE, null, cv);
}
}