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