如何使用ListView更正任何键入错误?

时间:2014-12-30 22:02:07

标签: android listview android-listview logcat android-logcat

它的logcat:

Process: com.example.SmsService, PID: 21748
java.lang.IndexOutOfBoundsException: Invalid index 6, size is 6
        at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
        at java.util.ArrayList.get(ArrayList.java:308)
        at com.example.SmsService.VideoView$3.getView(VideoView.java:168)
        at com.meetme.android.horizontallistview.HorizontalListView.fillListRight(HorizontalListView.java:753)
        at com.meetme.android.horizontallistview.HorizontalListView.fillList(HorizontalListView.java:695)
        at com.meetme.android.horizontallistview.HorizontalListView.onLayout(HorizontalListView.java:567)
        at android.view.View.layout(View.java:14891)
        at android.view.ViewGroup.layout(ViewGroup.java:4646)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1673)
        at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1662)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1438)
        at android.view.View.layout(View.java:14891)
        at android.view.ViewGroup.layout(ViewGroup.java:4646)
        at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
        at android.view.View.layout(View.java:14891)
        at android.view.ViewGroup.layout(ViewGroup.java:4646)
        at android.widget.RelativeLayout.onLayout(RelativeLayout.java:1055)
        at android.view.View.layout(View.java:14891)
        at android.view.ViewGroup.layout(ViewGroup.java:4646)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1673)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1527)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1436)
        at android.view.View.layout(View.java:14891)
        at android.view.ViewGroup.layout(ViewGroup.java:4646)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
        at android.view.View.layout(View.java:14891)
        at android.view.ViewGroup.layout(ViewGroup.java:4646)
        at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1673)
        at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1527)
        at android.widget.LinearLayout.onLayout(LinearLayout.java:1436)
        at android.view.View.layout(View.java:14891)
        at android.view.ViewGroup.layout(ViewGroup.java:4646)
        at android.widget.FrameLayout.layoutChildren(FrameLayout.java:453)
        at android.widget.FrameLayout.onLayout(FrameLayout.java:388)
        at android.view.View.layout(View.java:14891)
        at android.view.ViewGroup.layout(ViewGroup.java:4646)
        at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:2026)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1783)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1038)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5890)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:761)
        at android.view.Choreographer.doCallbacks(Choreographer.java:574)
        at android.view.Choreographer.doFrame(Choreographer.java:544)
        at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:747)
        at android.os.Handler.handleCallback(Handler.java:733)
        at android.os.Handler.dispatchMessage(Handler.java:95)
        at android.os.Looper.loop(Looper.java:136)
        at android.app.ActivityThread.main(ActivityThread.java:5118)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:515)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:606)
        at dalvik.system.NativeStart.main(Native Method)

显示此行中的任何输入错误:

 if (title.getText() == lines_image.get(position)) {
              Picasso.with(retval.getContext()).load(url_first + lines_image.get(position)).into(image_list_icon);
           }

这是我班上代码的all。可能是一个错误,因为我在lines_image中的数字 6 下的列表中没有该项,但我不知道如何避免它。请帮忙!!!!! 行将在哪里出错:

   if (title.getText() == lines_image.get(position)) {

以及我的所有代码getView()方法:

 @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View retval = LayoutInflater.from(parent.getContext()).inflate(R.layout.listview_leyout, parent, false);
        TextView title = (TextView) retval.findViewById(R.id.title);
        image_list_icon = (ImageView)retval.findViewById(R.id.image_fromlist);
       // title.setText(dataObjects[position%dataObjects.length]);

       title.setText(lines_image.get(position%lines_image.size()));


          if (title.getText() == lines_image.get(position)) {
              Picasso.with(retval.getContext()).load(url_first + lines_image.get(position)).into(image_list_icon);
           }

                ///// another, for video /////
                if (position == mSelectedItem) {
                    retval.setBackgroundColor(Color.WHITE);
                    retval.getBackground().setAlpha(80);
                    retval.setMinimumHeight(retval.getHeight() + 15);
                    image_list_icon.getLayoutParams().height = image_list_icon.getLayoutParams().height + 30;
                    image_list_icon.getLayoutParams().width = image_list_icon.getLayoutParams().width + 30;


                    if (title.getText() == lines_image.get( position)) {
                        String vidAddress = lines_video.get(position);
                        Uri vidUri = Uri.parse(vidAddress);
                        vidView.setVideoURI(vidUri);
                         vidView.start();
                    }


                } else if (position != mSelectedItem)

                {

                    image_list_icon.getLayoutParams().height = image_list_icon.getLayoutParams().height - 5;

                }
                return retval;
            }




};

1 个答案:

答案 0 :(得分:0)

将您的getCount()方法更改为

@Override
    public int getCount() {
    return lines_image.size();
} 

<强> 修改

如果您想要循环列表视图,则替换每次出现的

lines_image.get(position);

lines_image.get(position % lines_image.size());