Home Android SQLite / Response Exception in SQLite database
Reply: 0

Android SQLite / Response Exception in SQLite database

user2357
1#
user2357 Published in July 21, 2018, 1:51 pm

Code in one of four different fragments available from main activity file:

In MainActivity.java file:

onResponse() function:

sqliteDB db = new sqliteDB(getActivity());

if (db.selectRows(tempData.getPrimaryKey()) == 0)
{
    db.insertRow(tempData.getPrimaryKey(), [other attributes]);
}
else
{
    db.updateRow(tempData.getPrimaryKey(), [other attributes]);
}

onFailure() function:

sqliteDB db = new sqliteDB(getActivity());

List<String> tempDataList[] = db.selectRows();

for(int i = 0; i < tempDataList[0].size(); i++)
{
    myClass tempData = new myClass();

    tempData.setPrimaryKey(tempDataList[0].get(i));
    [other attributes]

    recoveryDataList.add(tempData);
}

    arrayList = new ArrayList<>();
    arrayList.addAll(recoveryDataList);
    recoveryListAdapter.notifyDataSetChanged();

Code in SQLite Database file:

In sqliteDB.java file:

public class sqliteDB extends SQLiteOpenHelper
{
    public Context con;

    public sqliteDB(Context context)
    {
        super(context, DATABASE_NAME, null, 1);
        // TODO Auto-generated constructor stub
        con = context;
    }

    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase)
    {
        // TODO Auto-generated method stub
        ...
    }

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1)
    {
        // TODO Auto-generated method stub
        ...
    }

    [Other insert, update, select and delete functions]

    ...
}

(Some true names of database attributes and some true names of all four different fragments available from main activity and functions have been removed).

Now, why does this piece of code throw with the following error?

E/Response Exception: Attempt to invoke virtual method 'android.database.sqlite.SQLiteDatabase android.content.Context.openOrCreateDatabase(java.lang.String, int, android.database.sqlite.SQLiteDatabase$CursorFactory, android.database.DatabaseErrorHandler)' on a null object reference

What is the way to fix it up?

Let me know if any more information is needed to answer with this question.

Thank you in advance.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.531992 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO