0
我正在使用一个名为find geopoint的按钮。点击那个按钮我应该去其他活动。在那个活动中,我已经在列表视图中显示数据库,但是当我点击该按钮时,应用程序崩溃。这里是我的代码:在android中显示数据库时发生错误
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));
}
请帮助我分享了2个活动之间的分贝它被称为geo_create_table
什么是'd'?是否初始化?你可以发布LogCat输出,以便我们看到你得到的错误是什么。我怀疑它可能是'd.getReadableDatabase()'处的'NullPointerException',但我无法确定。 –
请发布logcat日志。 – MByD