i have created a table named Ord in SQlite and the schema is :
sqlite> .schema
CREATE TABLE Ord (
int _id,
text Name
);
I use a function named insert_by_id and the code :
public void insert_by_id(int id){
ContentValues contentValues = new ContentValues();
contentValues.put(KEY_ID, id);
db.insert(TABLE_NAME2, null, contentValues);
}
ofcourse : private static final String TABLE_NAME2 = “Ord”;
and : public static final String KEY_ID = “_id”;
but when i’m trying to use it with the onClick event i get the error :
*01-11 02:13:38.622: E/Database(424): android.database.sqlite.SQLiteException: table Ord has no column named _id: , while compiling: INSERT INTO Ord(_id) VALUES(?);*
The part where i want to insert by id data is this :
plus[i].setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Salad_Num[k]++;
mySQLiteAdapter.insert_by_id(Salad_Num[k]);
quant.setText(""+Salad_Num[k]);
}
});
I guess there is no typo and as long as i have searched for similar answers here all of them are creating the database inside the code and not before trying to run the project.
SQL syntax error! you are trying to create a column “text” with data type “Name”. Check the correct syntax below, you have already fixed it i guess.