I'm getting NullpointerException. the follwing are my classes:
public class showrecordsBetweenDates extends Activity {
SQLiteDatabase db;
DBAdapter dbh;
.........
.........
.........
public Cursor getMeterRecords(){
dbh = new DBAdapter(showrecordsBetweenDates.this);
db = dbh.getWritableDatabase();
Cursor c;
String[] All_Columns = new String[] { DBAdapter.COLUMN_METER_ID, DBAdapter.COLUMN_METER_DATE, DBAdapter.COLUMN_METER_START, DBAdapter.COLUMN_METER_END };
c = db.query(DBAdapter.TABLE_METER, All_Columns, null, null, null, null, null);
if (c != null) {
c.moveToNext();
}
return c;
}
My adapter class is
public class MeterAdapter extends Activity {
SimpleCursorAdapter mycursor;
showrecordsBetweenDates showRecords;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.list_view_records);
showRecords= new showrecordsBetweenDates();
populateListview();
}
public void populateListview() {
Cursor cursor;
cursor = showRecords.getMeterRecords();
startManagingCursor(cursor);
String[] fromfields = new String[] {
DBAdapter.COLUMN_METER_DATE,
DBAdapter.COLUMN_METER_START,
DBAdapter.COLUMN_METER_END,
DBAdapter.COLUMN_METER_CAR_ID };
int[] tofields = new int[] {
R.id.meterdate,
R.id.meterstart,
R.id.meterend,
R.id.fk};
mycursor = new SimpleCursorAdapter(this, R.layout.row_meter, cursor,
fromfields, tofields, 0);
ListView mylist = (ListView) findViewById(R.id.list);
here is my error
02-20 03:31:12.823: E/AndroidRuntime(31264): at dalvik.system.NativeStart.main(Native Method)
02-20 03:31:12.823: E/AndroidRuntime(31264): Caused by: java.lang.NullPointerException
02-20 03:31:12.823: E/AndroidRuntime(31264): at com.munawwar.sultan.showrecordsdatewise.showrecordsBetweenDates.getMeterRecords(showrecordsBetweenDates.java:183)
02-20 03:31:12.823: E/AndroidRuntime(31264): at com.munawwar.sultan.cursoradapter.MeterAdapter.populateListview(MeterAdapter.java:39)
02-20 03:31:12.823: E/AndroidRuntime(31264): at com.munawwar.sultan.cursoradapter.MeterAdapter.onCreate(MeterAdapter.java:31)
02-20 03:31:12.823: E/AndroidRuntime(31264): at android.app.Activity.performCreate(Activity.java:5020)
02-20 03:31:12.823: E/AndroidRuntime(31264): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
02-20 03:31:12.823: E/AndroidRuntime(31264): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
02-20 03:31:12.823: E/AndroidRuntime(31264): ... 11 more
I populate listview from a method in DBAdapter class but now i need that method in another class(showrecordsBetweenDates) and i'm getting that error Thanks in Advance