I am a beginner at Android Studio... my code only works with 3 columns on the table, if add another field to the table, logcat will return:
no such column: "fone"
I have change the TABLE creation part of code and now it is returning another error (I don't know if the first error still exists):
SQLite Log: (1) near ")": syntax error
For sure the error is on the creation of the TABLE or the QUERY...
I have searched for the answer and the name of the field is not a KEYWORD, and I have tried to corrected the commas etc...
I think that the SelectionArguments is the solution, but I am unexperienced, I don't know exactly how to put the values there...
It's strange, because I added the field to the TABLE the same way I did to the others, but now it's returning these errors, the apk chrashes.
Here is the TABLE:
public void onCreate(SQLiteDatabase db) {
String livro = "CREATE TABLE livros " +
" ( " +
" id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL," +
" titulo TEXT NOT NULL," +
" autor TEXT NOT NULL," +
" pagina TEXT NOT NULL," +
" fone INTEGER," +
" )" ;
db.execSQL(livro);
The part of the QUERY:
String[] columns = {"id", "titulo", "autor", "pagina", "fone"};
Cursor cursor = getWritableDatabase().query("livros", columns, null, null, null, null, null, null);
ArrayList<Livros> livros = new ArrayList<Livros>();
while (cursor.moveToNext()){
Livros livro = new Livros();
livro.setId(cursor.getLong(0));
livro.setTitulo(cursor.getString(1));
livro.setAutor(cursor.getString(2));
livro.setPagina(cursor.getString(3));
livro.setFone((cursor.getInt(4))); ...