使用列表时发生错误

时间:2016-08-23 13:13:05

标签: vb.net

我有一个列表,我已使用此代码输入了五个项目:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
    android:id="@+id/list1"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" />
<ListView
    android:id="@+id/list2"
    android:layout_width="match_parent"
    android:layout_height="0dp"
    android:layout_weight="1" /></LinearLayout>

我正在尝试使用此代码查看这些项目:

     If (surname.Count + 1) < noofcompetitors Then
            surname.Add(txtSurname.Text)
     Else....

但是,我收到错误'System.ArgumentOutOfRangeException'。

1 个答案:

答案 0 :(得分:1)

为什么不在每个循环中使用a?

    For Each name As String In surname
        Console.WriteLine(name)
    Next

这样你就不会获得异常,你可以看到实际上有多少名字被添加到你的列表中