I am using a button called find geopoint. on clicking that button I am supposed to go to another activity. In that activity I have displayed the database in a listview but when I click that button the app crashes. Here’s my code:
public Display (String lat,String lon,String address ,String name1)
{
this.lat=lat;
this.lon=lon;
this.address=address;
Geo_Create_Table=name1;
}
public void display()
{
Log.d("hussain", lat);
db=d.getReadableDatabase();
Cursor c=db.query(Geo_Create_Table, new String[]{lat+"",lon+"",address}, null,null, null, null, null);
if (c != null)
{
c.moveToFirst(); // it's very important to do this action otherwise your Cursor object did not get work
int lat = c.getColumnIndex("latitude");
int lon = c.getColumnIndex("longitude");
int add = c.getColumnIndex("address");
if (c.isFirst())
{
int i = 0;
/* Loop through all Results */
do
{
i++;
String latitude1 = c.getString(lat);
String longitude1 = c.getString(lon);
String add1 = c.getString(add);
/* Add current Entry to results. */
results.add("" + i + ": " + latitude1 + " (" + longitude1 + ": " + add1 + ")");
} while (c.moveToNext());
}
}
this.setListAdapter(new ArrayAdapter(this, android.R.layout.simple_list_item_1, results));
}
pls help i have shared the db between 2 activities it is called geo_create_table
Without the LogCat output (please do post it so we can pinpoint the issue), I can only guess that one of
dorresultsis uninitialised, causing aNullPointerException. Neither of these are initialised in the constructor you posted, so this seems likely. It could also be thatresultsis not set up to take objects of typeString, but I doubt that’s it.