SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put(colDeptID, 1);
cv.put(colDeptName, "Sales");
db.insert(deptTable, colDeptID, cv);
cv.put(colDeptID, 2);
cv.put(colDeptName, "IT");
db.insert(deptTable, colDeptID, cv);
db.close();
With this code, I am getting a red underline under the parenthesis after put in every line and getting this error: Syntax error on token "(", delete this token.
I also get an error that says: Syntax error on tokens, variableDeclarator expected instead. Any ideas? I've tried everything I know to do, and none of it worked.
Edit: I also get Syntax error on "close", identifier expected after this token
I copy and pasted this code from a tutorial and all the comments said it worked, but I've had quite a few problems out of it. Thanks for such quick replies.
Only declarations, such as:
SQLiteDatabase db = this.getWritableDatabase();
ContentValues cv = new ContentValues();
can be directly inside a class declaration. Non-declarations, such as:
cv.put(colDeptID, 1);
cv.put(colDeptName, "Sales");
db.insert(deptTable, colDeptID, cv);
must be inside a method, constructor, initializer block, or static initializer block. In this case they should probably be in a constructor or method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With