I have created a menu database for a restaurant phone application however I encounter an error:
"Product() in Product cannot be applied to: menuitemid int, menuitemname string, menuitemprice int, menuitemdescription string, menuitemimgname string, menuitemorders int"
Find below my code:
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.content.Context;
import android.content.ContentValues;
import android.database.Cursor;
public class MenuDbHandler extends SQLiteOpenHelper {
private static final int menudatabaseversion = 1;
private static final String menudatabasename = "KWESPORTS.db";
private static final String menutablename = "MENUTABLE";
private static final String menucolumnid = "menuitemid";
private static final String menucolumnname = "menuitemname";
private static final String menucolumnprice = "menuitemprice";
private static final String menucolumndescription = "menuitemdescription";
private static final String menucolumnimgname = "menucolumnimgname";
private static final String menucolumnorders = "menucolumnorders";
public MenuDbHandler(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, menudatabasename, factory, menudatabaseversion);
}
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_MENU_TABLE = "CREATE TABLE " + menutablename + "(" + menucolumnid + " INTEGER PRIMARY KEY," + menucolumnname + " TEXT," + menucolumnprice + " INTEGER," + menucolumndescription + " TEXT," + menucolumnimgname + " TEXT," + menucolumnorders + "INTEGER" + ")";
db.execSQL(CREATE_MENU_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion){
db.execSQL("DROP TABLE IF EXISTS " + menutablename);
onCreate(db);
}
public Product findProduct (String menuitemname){
String query = "Select * FROM " + menutablename + " WHERE " + menucolumnname + " = \"" + menuitemname + "\"";
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(query, null);
Product product = new Product();
if (cursor.moveToFirst()) {
cursor.moveToFirst();
product.setmenuitemID(Integer.parseInt(cursor.getString(1)));
product.setmenuitemname(cursor.getString(2));
product.setmenuitemprice(Integer.parseInt(cursor.getString(3)));
product.setmenuitemdescription(cursor.getString(4));
product.setmenuitemimgname(cursor.getString(5));
product.setmenuitemorders(Integer.parseInt(cursor.getString(6)));
cursor.close();
} else {product = null;}
db.close();
return product;
}
}
And the Product java class:
public class Product {
private int _menuitemid;
private String _menuitemname;
private int _menuitemprice;
private String _menuitemdescription;
private String _menuitemimgname;
private int _menuitemorders;
public Product(int menuitemid, String menuitemname, int menuitemprice, String menuitemdescription, String menuitemimgname, int menuitemorders){
this._menuitemid = menuitemid;
this._menuitemname = menuitemname;
this._menuitemprice = menuitemprice;
this._menuitemdescription = menuitemdescription;
this._menuitemimgname = menuitemimgname;
this._menuitemorders = menuitemorders;}
public void setmenuitemID(int menuitemid) {this._menuitemid = menuitemid;}
public void setmenuitemname(String menuitemname) {this._menuitemname = menuitemname;}
public String getmenuitemname () {return this._menuitemname;}
public void setmenuitemprice (int menuitemprice) {this._menuitemprice = menuitemprice;}
public int getmenuitemprice () {return this._menuitemprice;}
public void setmenuitemdescription (String menuitemdescription) {this._menuitemdescription = menuitemdescription;}
public String getmenuitemdescription () {return this._menuitemdescription;}
public void setmenuitemimgname (String menuitemimgname) {this._menuitemimgname = menuitemimgname;}
public String getmenuitemimgname () {return this._menuitemimgname;}
public void setmenuitemorders (int menuitemorders) {this._menuitemorders = menuitemorders;}
public int getmenuitemorders () {return this._menuitemorders;}
}
Thanks, everyone!
Aucun commentaire:
Enregistrer un commentaire