我正在使用Android Studio.I在顯示ListView上的SQLite數據庫中顯示數據時遇到問題。 這裏是從SQLite的獲取數據(它工作得很好,選中)來自SQLite的Android Studio ListView
public List<Terminy> getAllItems(){
List<Terminy> itemList = new ArrayList<Terminy>();
String selectQuery = "SELECT id,data FROM Terminy WHERE Wolny = 1";
SQLiteDatabase database = this.getWritableDatabase();
Cursor cursor = database.rawQuery(selectQuery, null);
if(cursor.moveToFirst()){
do{
Terminy termin = new Terminy();
termin.setId2(Integer.parseInt(cursor.getString(0)));
termin.setData(cursor.getString(1));
itemList.add(termin);
}while(cursor.moveToNext());
}
cursor.close();
return itemList;
}
的方法和有方法把數據放入ListView的
public void ButtonLista(View v)
{
ArrayAdapter<Terminy> adapter;
ArrayList<Terminy> lista;
DatabaseHelper helper = new DatabaseHelper(this);
ListView listView = (ListView) findViewById(R.id.listView);
lista = new ArrayList<>(helper.getAllItems());
adapter = new ArrayAdapter<Terminy>(this,R.layout.activity_panel_uzytkownik, lista);
listView.setAdapter(adapter);
adapter.notifyDataSetChanged();
logcat的錯誤
com.example.czou.proojekt E/ArrayAdapter: You must supply a resource ID for a TextView com.example.czou.proojekt D/AndroidRuntime: Shutting down VM com.example.czou.proojekt W/art: Suspending all threads took: 02-08 17:47:59.352 1779-1779/com.example.czou.proojekt E/AndroidRuntime: FATAL EXCEPTION: main Process: com.example.czou.proojekt, PID: 1779 java.lang.IllegalStateException: ArrayAdapter requires the resource ID to be a TextView
有人能幫助我嗎?到目前爲止,我看了很多教程和仍然不知道如何解決我的問題:(
有什麼問題? – Blackbelt
我的方法不起作用。當我點擊按鈕在ListView上顯示數據時,我的應用程序停止並退出。 – Czunio
你是否介意分享stacktrace的異常/崩潰(aka * logcat *) – Blackbelt