SimpleCursorAdapter IllegalArgumentException

时间:2013-03-08 01:29:45

标签: c# android simplecursoradapter

我目前正在使用Visual Studio 2010和C#进行Android编程。编译时出错:Unhandled Exception: Java.Lang.IllegalArgumentException:有人可以解决这个问题吗?

这是我的代码:

         void GetCursorView()
          {
             Android.Database.ICursor icTemp = sql.GetRecordCursor();
             if (icTemp != null)
             {
             icTemp.MoveToFirst();
             ListView lvTemp = FindViewById(Resource.Id.lvtemp);
             string[] from = new string[] { "id", "fname", "age", "addr" };
              int[] to = new int[] {
              Resource.Id.t1,
              Resource.Id.t2,
              Resource.Id.t3,
              Resource.Id.t4
                };
          // creating a SimpleCursorAdapter to fill ListView object.
             SimpleCursorAdapter scaTemp = new SimpleCursorAdapter(this,Resource.Layout.recordview, icTemp, from, to); //error on this line
                     lvTemp.Adapter = scaTemp;
                            }
                        else
                         {
                         text.Text = sql.Message;
                            }
                      }

这是我的XML:

    <?xml version="1.0" encoding="utf-8"?>
    <AbsoluteLayout
        android:id="@+id/widget35"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android">
      <ListView
        android:id="@+id/lvtemp"
        android:layout_width="276dp"
        android:layout_height="147dp"
        android:background="#ff999999"
        android:padding="100dp"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:drawSelectorOnTop="true"
        android:gravity="center"
        android:layout_x="22dp"
        android:layout_y="0dp" 
        />
      <TextView
        android:id="@+id/t1"
        android:layout_width="268dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:layout_marginBottom="10dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:hint="ID"
        android:layout_x="27dp"
        android:layout_y="157dp" />
      <TextView
        android:id="@+id/t2"
        android:layout_width="264dp"
        android:layout_height="22dp"
        android:hint="Name"
        android:layout_x="30dp"
        android:layout_y="204dp" />
      <TextView
        android:id="@+id/t3"
        android:layout_width="261dp"
        android:layout_height="wrap_content"
        android:hint="age"
        android:layout_x="31dp"
        android:layout_y="244dp" />
      <TextView
        android:id="@+id/t4"
        android:layout_width="269dp"
        android:layout_height="wrap_content"
        android:hint="Address"
        android:layout_x="30dp"
        android:layout_y="282dp" />
      <

        Button
            android:id="@+id/b1"
            android:layout_width="182dp"
            android:layout_height="wrap_content"
            android:text="OK"
            android:layout_x="77dp"
            android:layout_y="324dp" />

    </AbsoluteLayout>

1 个答案:

答案 0 :(得分:0)

我认为不是

SimpleCursorAdapter scaTemp = new SimpleCursorAdapter(this,Resource.Layout.recordview, icTemp, from, to); 

DO

SimpleCursorAdapter scaTemp = new SimpleCursorAdapter(this, icTemp,Resource.Layout.recordview, from, to);