ListView.layoutChildren中的方向特定故障 - 异常ArrayIndexOutofBoundsException

时间:2010-09-20 23:35:38

标签: android exception listview

我是一个非常绿色的Android开发人员,需要一些奇怪的程序崩溃的帮助。通常程序运行得很好。它失败的可能性相等(最后看到堆栈)。我可以看到程序通过getView函数运行,一切看起来都是有序的(即所有信息都按预期存在并通过convertView看似很好)。要么它会经历几次,然后程序将是A-OK,否则它将失败,如下所示,我无法找出导致崩溃的原因。更奇怪的是,如果我以横向模式握住手机,它永远不会失败!!它只能在纵向方向上失败大约50%的时间。有人可以帮帮我吗?

        @Override
    public View getView(int position, View convertView, ViewGroup parent){

        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.row, null);
        }
        ADDPResults addpres = items.get(position);
        if (addpres != null) {
                //initialize display variables from inflated row.xml variables
                TextView iptext = (TextView) v.findViewById(R.id.IPtext);
                TextView mactext = (TextView) v.findViewById(R.id.MACtext);
                TextView nametext = (TextView) v.findViewById(R.id.Nametext);
                TextView devicetext = (TextView) v.findViewById(R.id.Devicetext);
                //TextView firmwaretext = (TextView) v.findViewById(R.id.Firmwaretext);
                //write the real data to the display
                iptext.setText("IP Address:     "+addpres.addp_deviceIP.toDecString()); 
                mactext.setText("MAC Address: "+addpres.addp_deviceMAC.toHexString() );
                nametext.setText("Name:             "+addpres.addp_devName);
                devicetext.setText("Device:           "+addpres.addp_devType);       
                //firmwaretext.setText("Firmware:       "+addpres.addp_FWVersion);
        }
        return v;
    }
}

----------------------- ------------失败----------------------- 线程[< 3> main](Suspended(异常ArrayIndexOutOfBoundsException))  ListView.layoutChildren()行:1686  ListView(AbsListView).onLayout(boolean,int,int,int,int)行:1224  ListView(View).layout(int,int,int,int)行:6886  LinearLayout.setChildFrame(View,int,int,int,int)行:1119  LinearLayout.layoutVertical()行:998  LinearLayout.onLayout(boolean,int,int,int,int)行:918  LinearLayout(View).layout(int,int,int,int)行:6886  FrameLayout.onLayout(boolean,int,int,int,int)行:333  FrameLayout(View).layout(int,int,int,int)行:6886  LinearLayout.setChildFrame(View,int,int,int,int)行:1119  LinearLayout.layoutVertical()行:998  LinearLayout.onLayout(boolean,int,int,int,int)行:918  LinearLayout(View).layout(int,int,int,int)行:6886  PhoneWindow $ DecorView(FrameLayout).onLayout(boolean,int,int,int,int)行:333  PhoneWindow $ DecorView(View).layout(int,int,int,int)行:6886  ViewRoot.performTraversals()行:996  ViewRoot.handleMessage(消息)行:1633  ViewRoot(Handler).dispatchMessage(Message)行:99  Looper.loop()行:123  ActivityThread.main(String [])行:4363  Method.invokeNative(Object,Object [],Class,Class [],Class,int,boolean)line:not available [native method]  Method.invoke(Object,Object ...)行:521  ZygoteInit $ MethodAndArgsCaller.run()行:862  ZygoteInit.main(String [])行:620  NativeStart.main(String [])行:不可用[本机方法]

1 个答案:

答案 0 :(得分:1)

我会检查你得到的'位置'并将其与你的items数组的大小进行比较......因为异常说:ArrayIndexOutOfBoundsException