I guess it’s some basic mistake since I’m still a rookie.
package pl.cashflowmanager;
//all necessary imports are here
public class SummaryOverMonths extends ExpandableListActivity {
private CfmDbAdapter db;
private final Cursor monthsCountQuery = db.SQLDb.rawQuery("select * from expenses", null); //crashes here with: 12-10 12:51:15.101: E/AndroidRuntime(348): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{pl.cashflowmanager/pl.cashflowmanager.SummaryOverMonths}: java.lang.NullPointerException
//rest code goes there
I commented the problem. The query is fine, the database is working. Should the cursor go inside the method or what?
You’re getting a
NullPointerExceptionbecause you haven’t instantiated theCfmDbAdapteryet. You have created a field for it, yes, but you haven’t put anything in it before trying to call your query on it.So you’re asking a non-existing item to perform an action, causing the
NullPointer.Instantiate it first like so:
That should do the trick.