私は2 EditText
を入力しました。ユーザーが送信をクリックすると、値はListview
アダプターに追加されます。値はStringTokenizer
で区切られています。最初のEditText
が空でappがforce closed
のときにNoSuchElementException
が検出されます。だから私はtry-catch
を含め、それはもはや強制終了しませんでした。しかし今、ユーザーが入力した値は行に追加されません。アイテムはまだ追加されていますが、値はありません。この例外はどのように解決するのですか?Android - NoSuchElementExceptionのListView問題
つまり、例外のためにtry-catch
を追加した後、itemの値は空です。このような例外をキャッチ
Adapter.java
public View getView(final int position, View convertView, ViewGroup parent)
{
View row = convertView;
if(row == null)
{
LayoutInflater inflater = getLayoutInflater();
row = inflater.inflate(R.layout.custom_list_item, null);
}
try
{
StringTokenizer tokens = new StringTokenizer(noteList.get(position), ":");
String first = tokens.nextToken();
String second = tokens.nextToken();
row.getTag();
((TextView)row.findViewById(R.id.nametv)).setText(first);
((EditText)row.findViewById(R.id.result)).setText(second);
}
catch (NoSuchElementException f)
{
}
}