[Solved] How to pass a variable from an activity to a class?

You can just instantiate your database class in your activity OpenHelper mOpenHelper = new OpenHelper(this); And create a method in your db class to create your tables public void createTable(String nomelistafinal ) { final SQLiteDatabase db = getWritableDatabase(); db.execSQL(“CREATE TABLE ” + nomelistafinal + ” (codigo text not null) “); db.close(); } 0 solved How … Read more

[Solved] Android SQlite exceptions which cause the app to crash [closed]

Check this error here. Process: com.example.rockodile.contactsappliaction, PID: 5549 java.lang.IllegalStateException: Couldn’t read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it. at android.database.CursorWindow.nativeGetString(Native Method) at android.database.CursorWindow.getString(CursorWindow.java:438) at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51) at com.example.rockodile.contactsappliaction.UserSQL.getContactList(UserSQL.java:105) at com.example.rockodile.contactsappliaction.MainActivity.onClick(MainActivity.java:52) Update. public ArrayList<HashMap<String, String>> getContactList() { //Open connection to read only SQLiteDatabase db = dbHelper.getReadableDatabase(); … Read more

[Solved] Nullpointer Exception in SQL, Listivew

Your class member model from class InputTab has never initialized. Therefore, you got a NPE at line model.requery();. That’s why you saved your data, but right after that, you got a NPE. You don’t need any Cursor in this class and, of course, you don’t need to requery() anything. 2 solved Nullpointer Exception in SQL, … Read more

[Solved] How to count the number of instances of a substring in sqlite or duckdb across all rows?

Here’s a great answer from the DuckDB people: Two functions will do the trick for you! String_split, and unnest. Unnest is a special function that takes lists and creates a separate row for each element. With lists_split_into_rows as ( select col1, unnest(string_split(col2, ‘ ‘)) as new_column from my_table ) Select new_column, count(*) as my_count from … Read more

[Solved] Order Data in SQLite Android [closed]

You have an error concatenating your SQL statement: String selectQuery = “SELECT * FROM ” + TABLE_MURIDD + “ORDER BY” + COLUMN_NOMOR + “ASC”; should be: String selectQuery = “SELECT * FROM ” + TABLE_MURIDD + ” ORDER BY ” + COLUMN_NOMOR + ” ASC”; EDIT: (Thanks to Michael Dogg) A better way of protecting … Read more

[Solved] Android cursor out of bounds exception

Replace your below code cursor.moveToFirst(); Note newNote=cursorToNote(cursor); cursor.close(); return newNote; With if (cursor != null && cursor.moveToFirst()) { Note newNote=cursorToNote(cursor); cursor.close(); return newNote; } else { return null; } 4 solved Android cursor out of bounds exception

[Solved] Get value from SQLite database:

To get value or multiple values you need a cursor, see the following function (that return the first value it’s perfect to get id’s, for example): public String getSingular_Value_InTransaction(String query){ //Declaration of variables Cursor a1 = null; try{ a1 = database.rawQuery(query,null); a1.moveToFirst(); if(a1.getString(0) != null){ String result = a1.getString(0); a1.close(); return result; } else{ a1.close(); … Read more