【问题标题】:Orientation specific failure in ListView.layoutChildren -- exception ArrayIndexOutofBoundsExceptionListView.layoutChildren 中的特定方向失败——异常 ArrayIndexOutofBoundsException
【发布时间】:2011-04-14 22:51:01
【问题描述】:

我是一个非常绿色的 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;
    }
}

-----------失败----------- ---------------------- 线程 [ main](暂停(异常 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(Message) 行:1633 ViewRoot(Handler).dispatchMessage(Message) 行:99 Looper.loop() 行:123 ActivityThread.main(String[]) 行:4363 Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) 行:不可用 [本机方法] Method.invoke(Object, Object...) 行:521 ZygoteInit$MethodAndArgsCaller.run() 行:862 ZygoteInit.main(String[]) 行:620 NativeStart.main(String[]) 行:不可用 [本机方法]

【问题讨论】:

    标签: android exception listview


    【解决方案1】:

    我会检查您得到的“位置”并将其与您的项目数组的大小进行比较...因为异常显示:ArrayIndexOutOfBoundsException

    【讨论】:

    • 我查过了。通常数组中有 5 个项目,并且“位置”永远不会像预期的那样超过 4。通常崩溃会发生在“Position=4”迭代中,但并非总是如此。
    猜你喜欢
    • 2011-06-06
    • 2016-10-07
    • 1970-01-01
    • 2016-09-20
    • 1970-01-01
    • 2015-03-23
    • 1970-01-01
    • 2015-02-26
    • 2013-12-01
    相关资源
    最近更新 更多