NullPointerException error [closed]

2
  

Caused by: java.lang.NullPointerException        at DAO.Database.ScheduleReview (Database.java:184)

This error was displayed in my logcat .

The method:

public boolean verificaSeTemRegistroNaTabela(String tabela){
    String sqlSelect = "SELECT * FROM '" + tabela + "'";
    Cursor res = db.rawQuery(sqlSelect, null);
    if (res.getCount() > 0){
        return true;
    }
    return false;
}

Line with error:

Cursor res = db.rawQuery(sqlSelect, null);
    
asked by anonymous 17.11.2016 / 19:56

1 answer

1

As quoted in the comments by Virgilio, his mistake is to pass the table with single quotation marks.

Get the value of sqlSelect and run in your database, the error will occur.

Passing parameters to sql commands always passing bind variables will make your code safer and easier to maintain in the future.

    
18.11.2016 / 11:01