-1

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))); ...
bruno.bm6
  • 17
  • 6
  • As well as the issue highlighted by Maloubobola, You are possibly not understanding the database create vs upgrade differences. Read this: http://stackoverflow.com/questions/21881992/when-is-sqliteopenhelper-oncreate-onupgrade-run – Kuffs Nov 13 '15 at 15:56
  • Clear the data of your app or uninstall it and then test it again. – madlymad Nov 14 '15 at 18:40

2 Answers2

4

You have an extra , after this line (in the CREATE request)

fone INTEGER,

just remove it

ThomasThiebaud
  • 11,331
  • 6
  • 54
  • 77
  • 2
    Then uninstall and reinstall your app, in order for the database to be recreated new. – Phantômaxx Nov 13 '15 at 15:54
  • Well, now the app opens and it seems the app is saving the registers... but when the finger press to open the register, nothing happens... do you have any idea? your answer was simple but helped a lot, thanks. – bruno.bm6 Nov 13 '15 at 16:50
  • 1
    Currently no. But this seems to be a new problem, so post a new question with the minimum resources to try to solve it. – ThomasThiebaud Nov 13 '15 at 17:28
0
" fone INTEGER," +
                   " )" ;

should be

" fone INTEGER)" ;

You don't use a comma after the last column.