如何在android中修复错误“不幸关闭myapp”?

时间:2015-01-31 06:43:54

标签: android android-listview

在我的应用中,我有listview。如果我单击列表中的某个项目,它将遍历另一个使我编辑值的意图。只有一个listitem,它不适合我。它会关闭应用程序。我检查了logcat。我将其视为IndexOutOfBound例外。无法修复它。请帮帮我。

lvDetail.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id)
            {
                HashMap<String, String> map = new HashMap<String, String>();
                map = valuesList.get(position);

                DesigId = map.get(Desig_ID);
                DesigName = map.get(Desig);
                Desc1 = map.get(Desc);

                Intent in = new Intent(ViewAndUpdate.this, EnterDetails.class);
                in.putExtra("DesigId", "" + DesigId);
                in.putExtra("Desig", "" + DesigName);
                in.putExtra("Desc", "" + Desc1);
                startActivity(in);

            }
        });

这是logcat部分:

01-31 12:17:32.693: E/AndroidRuntime(2263): FATAL EXCEPTION: main
01-31 12:17:32.693: E/AndroidRuntime(2263): java.lang.IndexOutOfBoundsException: Invalid index 10, size is 10
01-31 12:17:32.693: E/AndroidRuntime(2263):     at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:251)
01-31 12:17:32.693: E/AndroidRuntime(2263):     at java.util.ArrayList.get(ArrayList.java:304)

1 个答案:

答案 0 :(得分:0)

它说size is 10表示0到9,但你的位置是10!尝试positon-1而不是position