gpt4 book ai didi

java - 初学者Java android studio错误

转载 作者:行者123 更新时间:2023-12-02 02:20:11 24 4
gpt4 key购买 nike

我刚刚开始学习 java/android studio,目前正在按照 youtube 教程构建 SQLite 数据库。我遇到了一些无法解决的错误。

public class DatabaseHelper extends SQLiteOpenHelper {
public static final string DATABASE_NAME = "skinApp.db";
public static final string TABLE_NAME = "products_table";
public static final String COLUMN_TASKID = "_id";
public static final String COLUMN_PHOTO = "Photo";
public static final String COLUMN_NAME = "Product name";
public static final String COLUMN_DETAILS = "Details";
public static final String COLUMN_PRICE = "Price";
public static final String COLUMN_BRAND = "Brand";
public static final String COLUMN_TAGS = "Tags";

public DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, 1);
SQLiteDatabase db = this.getWritableDatabase();
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_NAME + " (ID INTEGER PRIMARY KEY AUTOINCREMENT, PHOTO BLOB, PRODUCTNAME TEXT, DETAILS TEXT, PRICE DECIMAL, BRAND TEXT, TAGS TEXT");
}
@Override
public void onUpgrade(SQLiteDatabase db int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}

在最后两个@override中,我的错误是这样的

'method cannot ovverride method from its superclass'

以及 super 之后括号中的文本(我的错误是:

Object in Object() cannot be applied to ... [all parameters stated]

这些错误是什么意思,我该如何修复它?

最佳答案

像这样创建表,您的 DataBaseHelper 类上还有另一个错误,您没有初始化数据为 TEXT 或 VARCHAR :

 String createTable = " CREATE TABLE "+ Constants.TABLE_NAME +"(ID INTEGER PRIMARY KEY AUTOINCREMENT, "+Constants.NAME+" TEXT, "+Constants.SKU+" TEXT ,"+Constants.UPC+" TEXT,"+Constants.ASSOC_UPC+" TEXT,"+Constants.PRICE+" TEXT, "+Constants.DISPLAY_SIZE+" TEXT, "+Constants.DISPLAY_SIZE_YES+" INTEGER , "+Constants.STATUS+" TEXT)";
db.execSQL(createTable);

这是我的 DataBaseHelper 类,尝试理解它,我正在创建两个表:

public class DatabaseHelper extends SQLiteOpenHelper {
private static final String TAG = "DatabaseHelper";
private static final String DATABASE_NAME = "GiftsDatabase.db";
SQLiteDatabase db;

public DatabaseHelper(Context context) {
super(context, DATABASE_NAME,null,Constants.DATABASE_VERSION);
}



@Override
public void onCreate(SQLiteDatabase db) {
try{
String createTable = " CREATE TABLE "+ Constants.TABLE_NAME +"(ID INTEGER PRIMARY KEY AUTOINCREMENT, "+Constants.NAME+" TEXT, "+Constants.SKU+" TEXT ,"+Constants.UPC+" TEXT,"+Constants.ASSOC_UPC+" TEXT,"+Constants.PRICE+" TEXT, "+Constants.DISPLAY_SIZE+" TEXT, "+Constants.DISPLAY_SIZE_YES+" INTEGER , "+Constants.STATUS+" TEXT)";
db.execSQL(createTable);
String createTableCount = " CREATE TABLE "+ Constants.TABLE_NAME_COUNT +"(ID INTEGER PRIMARY KEY AUTOINCREMENT, "+Constants.SKU_COUNT+" TEXT ,"+Constants.QUANTITY_COUNT+" TEXT)";
db.execSQL(createTableCount);

Log.e(TAG,"Created Database");
}catch (Exception e){
Log.e("EXCEPTION",""+e);
}

}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(" DROP TABLE IF EXISTS "+Constants.TABLE_NAME);
db.execSQL(" DROP TABLE IF EXISTS "+Constants.TABLE_NAME_COUNT);
onCreate(db);
}

public boolean addData(String name , String sku, String upc ,String assocUpc, String price, String displaySize, int displaySizeYes, String status){
db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
contentValues.put(Constants.NAME, name );
contentValues.put(Constants.SKU, sku );
contentValues.put(Constants.UPC, upc );
contentValues.put(Constants.ASSOC_UPC, assocUpc );
contentValues.put(Constants.PRICE, price );
contentValues.put(Constants.DISPLAY_SIZE, displaySize );
contentValues.put(Constants.DISPLAY_SIZE_YES, displaySizeYes );
contentValues.put(Constants.STATUS, status );

long result = db.insert(Constants.TABLE_NAME,null,contentValues);
Log.e(TAG,""+upc+" Inserted");
Log.e(TAG,""+assocUpc+" Inserted");

if(result == -1) {
return false;
}else{
// Log.e(TAG,"value inserted");
return true;
}

}

public boolean addDataCount(String skuCount,String quantityCount ){
db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
// contentValues.put(Constants.UPC_COUNT,upcCount);
contentValues.put(Constants.SKU_COUNT,skuCount);
contentValues.put(Constants.QUANTITY_COUNT,quantityCount);

long result = db.insert(Constants.TABLE_NAME_COUNT,null,contentValues);
Log.e(TAG,""+skuCount+" Inserted");

if(result == -1) {
return false;
}else{
Log.e(TAG,"value inserted");
return true;
}


}

public boolean deleteTable(){
db = this.getWritableDatabase();
db.execSQL("delete from "+ Constants.TABLE_NAME);
Log.e("DELETE_TABLE","DELETE_TABLE");
return true;

}
public boolean deleteTableCount(){
db = this.getWritableDatabase();
db.execSQL("delete from "+ Constants.TABLE_NAME_COUNT);
Log.e("DELETE_TABLE_COUNT","DELETE_TABLE_COUNT");
return true;

}


}

关于java - 初学者Java android studio错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48610278/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com