I'm trying to retrieve some data from a table using a Cursor to display it in a TextView, but I'm getting an error.
Please care to help me.
Here's my code
public class DisplayBudget extends AppCompatActivity implements View.OnClickListener {
SQLiteDatabase db;
TextView bname,name,limit;
Button del;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.budget_details);
bname = (TextView) findViewById(R.id.textViewbname);
name = (TextView) findViewById(R.id.textViewname);
limit = (TextView) findViewById(R.id.textViewlimit);
del = (Button) findViewById(R.id.button2);
del.setOnClickListener(this);
DBController dbController = new DBController(this);
dbController.openToDisplay();
Cursor cursor = db.rawQuery(" select *from "+DBHelper.TABLE_NAME+ " where id = 1 ",null);
cursor.moveToFirst();
name.append(cursor.getString(cursor.getColumnIndex(DBHelper.OWNER_NAME)));
bname.append(cursor.getString(cursor.getColumnIndex(DBHelper.BUDGET_NAME)));
limit.append(cursor.getString(cursor.getColumnIndex(DBHelper.BUDGET_LIMIT)));
cursor.close();
}
Here's the LogCat
12-25 00:39:46.440 30123-30123/com.example.rajkumar.budget W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0xb0d40b20)
12-25 00:39:46.440 30123-30123/com.example.rajkumar.budget E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.example.rajkumar.budget, PID: 30123
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.rajkumar.budget/com.example.rajkumar.budget.DisplayBudget}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.rajkumar.budget.DisplayBudget.onCreate(DisplayBudget.java:28)
at android.app.Activity.performCreate(Activity.java:5231)