Skip to content Skip to sidebar Skip to footer

Looking For Cause Of Null Pointer Exception

I'm sure there's something simple behind the error Null Pont Exception error I am getting, but, I don't see it. Here's the relevant code: package com.example.gameexpensetracker;

Solution 1:

Your DBAdapter.rawQuery() is not implemented, it's just a stub that returns null. Attempting to call moveToFirst() on this null reference causes the NPE.

That is, change

publicCursorrawQuery(Stringstring, Objectobject) {
    // TODO Auto-generated method stubreturnnull;
}

to something like

publicCursorrawQuery(String sql, String[] args) {
    return db.rawQuery(sql, args);
}

Solution 2:

It seems the variable cursor17 is null. Maybe in your situation this changed if-condition helps:

if(cursor17!=null&&cursor17.moveToFirst()) {

I don't know your DBAdapter class, but is the second parameter to your rawQuery()-method not set to null, meaning you get null if your table strategyTotal is empty? I would look if the table is empty and why and what result your query will then deliver.

Solution 3:

Move db initialization to onCreate

DBAdapter db; 
protectedvoidonCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.chart_screen_activity);
db = newDBAdapter(this); 

Post a Comment for "Looking For Cause Of Null Pointer Exception"