Situation disadvantage in ListView.layoutChildren - ArrayIndexOutofBoundsException exception

I am a very green Android developer and need help with a weird program crash. Often the program will work fine. There is an equal chance that it will fail (see Stack at the end). I can see how the program is launched through the getView function, and everything looks in order (i.e. all the information there, as expected, and passes through the convertView, would seem to be excellent). Either this will go through several times, and then the program will be A-OK or it will fail, as shown below, and I could not determine the cause of the failure. Even stranger is that if I hold the phone in landscape mode, it will never fail !! This occurs only about 50% of the time in portrait orientation. Can someone please help me?

        @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;
    }
}

----------------------- ----------------------- Failure ----------------------- [< 3 > main] ( ( ArrayIndexOutOfBoundsException))  ListView.layoutChildren(): 1686  ListView (AbsListView).onLayout(boolean, int, int, int, int): 1224  ListView (View).layout(int, int, int, int): 6886  LinearLayout.setChildFrame(, int, int, int, int) : 1119  LinearLayout.layoutVertical() line: 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(, int, int, int, int) : 1119  LinearLayout.layoutVertical() line: 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(Message): 1633  ViewRoot (Handler).dispatchMessage(Message): 99  Looper.loop(): 123  ActivityThread.main( []): 4363  Method.invokeNative(Object, Object [], Class, Class [], Class, int, boolean) : [native method]   Method.invoke(Object, Object...): 521   ZygoteInit $MethodAndArgsCaller.run(): 862  ZygoteInit.main( []): 620  NativeStart.main( []) : [ ]

+3
1

, "", ... : ArrayIndexOutOfBoundsException

+1

Source: https://habr.com/ru/post/1765728/


All Articles