here such error jumps out (did not copy all logs, only the very first)

FATAL EXCEPTION: main Process: com.example.dimantik.myapplication, PID: 19084 java.lang.IllegalArgumentException: the bind value at index 1 is null at android.database.sqlite.SQLiteProgram.bindString(SQLiteProgram.java:164) at android.database.sqlite.SQLiteProgram.bindAllArgsAsStrings(SQLiteProgram.java:200) at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:47) at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1346) at android.database.sqlite.SQLiteDatabase.queryWithFactory(SQLiteDatabase.java:1193) at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1064) at android.database.sqlite.SQLiteDatabase.query(SQLiteDatabase.java:1232) at com.example.dimantik.myapplication.ShowCategoryTaskFragment.getTaskNames(ShowCategoryTaskFragment.java:80) at com.example.dimantik.myapplication.ShowCategoryTaskFragment.onStart(ShowCategoryTaskFragment.java:51) 

That's what swears

 public String[] getTaskNames(){ SQLiteOpenHelper openHelper = new TaskOpenHelper(getContext()); SQLiteDatabase db = openHelper.getReadableDatabase(); Cursor cursor = db.query("TASK1", new String[]{"NAME"}, "CATEGORY = ?", new String[]{category}, null, null, null); cursor.moveToFirst(); if (cursor.getCount() == 0){ return new String[0]; }else { String[] taskNames = new String[cursor.getCount()]; int i = 0; String names = ""; do { names = names + cursor.getString(0); taskNames[i] = cursor.getString(0); i++; }while (cursor.moveToNext()); return taskNames; } } 

Swears on cursor initialization

  • one
    And category is not exactly null ? .. - Yuriy SPb

2 answers 2

Check the place where you initialize category . It seems that at that moment when you call query , category == null . If you want category to be null , do the following:

 String tableName = "TASK1"; String[] columns = {"NAME"}; String whereNotNull = "CATEGORY = ?"; String whereNull = "CATEGORY IS NULL"; String[] whereArgs = { category }; Cursor cursor = whereArgs == null ? db.query(tableName, columns, whereNull, null, null, null, null) : db.query(tableName, columns, whereNotNull, whereArgs, null, null, null); 
     names = names + cursor.getString(0); taskNames[i] = cursor.getString(0); 

    Tried to replace 0 with i ? You're like the data from the cursor on the position trying to pull.