私のアプリケーションでは、CustomAdapter を使用して ListView のレイアウトを設定したいと考えています。
これは私のエラーログです:
05-09 19:17:50.187: E/AndroidRuntime(32063): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.unserekinder/com.example.unserekinder.Ereignisse}: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
05-09 19:17:50.187: E/AndroidRuntime(32063): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
05-09 19:17:50.187: E/AndroidRuntime(32063): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
05-09 19:17:50.187: E/AndroidRuntime(32063): at android.app.ActivityThread.access$600(ActivityThread.java:141)
05-09 19:17:50.187: E/AndroidRuntime(32063): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
05-09 19:17:50.187: E/AndroidRuntime(32063): at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 19:17:50.187: E/AndroidRuntime(32063): at android.os.Looper.loop(Looper.java:137)
05-09 19:17:50.187: E/AndroidRuntime(32063): at android.app.ActivityThread.main(ActivityThread.java:5041)
05-09 19:17:50.187: E/AndroidRuntime(32063): at java.lang.reflect.Method.invokeNative(Native Method)
05-09 19:17:50.187: E/AndroidRuntime(32063): at java.lang.reflect.Method.invoke(Method.java:511)
05-09 19:17:50.187: E/AndroidRuntime(32063): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-09 19:17:50.187: E/AndroidRuntime(32063): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-09 19:17:50.187: E/AndroidRuntime(32063): at dalvik.system.NativeStart.main(Native Method)
05-09 19:17:50.187: E/AndroidRuntime(32063): Caused by: java.lang.IllegalStateException: Couldn't read row 0, col -1 from CursorWindow. Make sure the Cursor is initialized correctly before accessing data from it.
05-09 19:17:50.187: E/AndroidRuntime(32063): at android.database.CursorWindow.nativeGetString(Native Method)
05-09 19:17:50.187: E/AndroidRuntime(32063): at android.database.CursorWindow.getString(CursorWindow.java:434)
05-09 19:17:50.187: E/AndroidRuntime(32063): at android.database.AbstractWindowedCursor.getString(AbstractWindowedCursor.java:51)
05-09 19:17:50.187: E/AndroidRuntime(32063): at com.example.unserekinder.Ereignisse.datenfuerlistviewereignis(Ereignisse.java:51)
05-09 19:17:50.187: E/AndroidRuntime(32063): at com.example.unserekinder.Ereignisse.onCreate(Ereignisse.java:29)
05-09 19:17:50.187: E/AndroidRuntime(32063): at android.app.Activity.performCreate(Activity.java:5104)
05-09 19:17:50.187: E/AndroidRuntime(32063): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
05-09 19:17:50.187: E/AndroidRuntime(32063): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
05-09 19:17:50.187: E/AndroidRuntime(32063): ... 11 more
これは、EreignislistAdapter と呼ばれる私の CustomAdapter です。
public class EreignislistAdapter extends BaseAdapter
{
private final ArrayList<Ereignis> values;
private final LayoutInflater inflator;
public EreignislistAdapter (Context context, ArrayList<Ereignis> values){
this.inflator = LayoutInflater.from(context);
this.values = values;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolderEreignis holder;
if(convertView == null){
convertView = inflator.inflate(R.layout.list_ereignis, parent, false);
holder = new ViewHolderEreignis((TextView) convertView.findViewById(R.id.enullline), (TextView) convertView.findViewById(R.id.efirstLine));
convertView.setTag(holder);
}
else{
holder = (ViewHolderEreignis) convertView.getTag();
}
Ereignis ki = (Ereignis) getItem(position);
holder.getEreignisname().setText(ki.getEreignisname());
holder.getEreignisdatum().setText(ki.getEreignisZeit());
return convertView;
}
@Override
public int getCount() {
return values.size();
}
@Override
public Object getItem(int position) {
return values.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
}
class ViewHolderEreignis {
private TextView ereignisname = null;
private TextView ereignisdatum = null;
public ViewHolderEreignis(TextView ereignisname, TextView ereignisdatum) {
this.ereignisname = ereignisname;
this.ereignisdatum = ereignisdatum;
}
public TextView getEreignisname() {
return this.ereignisname;
}
public TextView getEreignisdatum(){
return this.ereignisdatum;
}
}
そして、これは私のDBHelper
声明です
public static final String ereignisid = "id";
public static final String TABLE_NAME_EREIGNIS="ereignis";
public static final String EREIGNISNAME = "ereignisname";
public static final String EREIGNISZEIT = "ereigniszeit";
public static final String EREIGNISGENAUERES = "ereignisgenaueres";
public static final String KINDID = "kindid";
private static final String TABLE_EREIGNIS_CREATE = "CREATE TABLE IF NOT EXISTS " + TABLE_NAME_EREIGNIS + " (" + ereignisid + " INTEGER PRIMARY KEY AUTOINCREMENT, "
+ EREIGNISNAME + " TEXT, " + EREIGNISZEIT + " TEXT, " + EREIGNISGENAUERES + " TEXT, " + KINDID + " INTEGER, FOREIGN KEY (" + KINDID + ") REFERENCES " + TABLE_NAME_Kind + "(" + id + "));";
私のアダプターは次のように呼び出されます:
final ListView lv = (ListView) findViewById(R.id.lvEreignisse);
ArrayList<Ereignis> kisi = datenfuerlistviewereignis();
EreignislistAdapter kiadapter = new EreignislistAdapter(this, kisi);
lv.setAdapter(kiadapter);
Here is `datenfuerlistviewereignis`:
private ArrayList<Ereignis> datenfuerlistviewereignis(){
DBHelper db = new DBHelper(this);
ArrayList<Ereignis> arr = new ArrayList<Ereignis>();
ListView lv = (ListView) findViewById(R.id.lvEreignisse);
id = getIntent().getIntExtra("kinderid", 0);
Cursor c = db.selectEreignis(id);
int count = c.getCount();
System.out.println("SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS" +count);
int i = 0;
while(c.moveToNext())
{
arr.add(new Ereignis(c.getString(c.getColumnIndex("ereigniszeit")), c.getString(c.getColumnIndex("ereignisname")) ));
i++;
}
if(arr.size() > 0){
return arr;
}
else{
ArrayList<Ereignis> arrempty = new ArrayList<Ereignis>();
arrempty.add(new Ereignis("Keine Daten vorhanden", " "));
return arrempty;
}
}
Ereignis
だから、自分の に追加しようとすると問題があるに違いないことはわかっていArrayList
ます。また、createステートメントとの関連があると思いますが、間違いを見つけることができません。誰かが私を助けることができますか?