2010-09-20 26 views
3

我是一个非常绿色的android开发人员,需要一些奇怪的程序崩溃帮助。程序通常运行得很好。有一个相同的机会会失败(见最后的堆栈)。我可以通过getView函数观察程序运行情况,看起来一切正常(即所有信息都按预期方式出现,并通过convertView看起来很好)。要么它会经历几次,然后程序将是A-OK,否则它会失败,如下所示,我无法找出导致崩溃的原因。更奇怪的是,如果我将手机放在横向模式下,它永远不会失败!它只能在纵向取向中失败大约50%的时间。有人可以帮帮我吗?ListView.layoutChildren中的方向特定故障 - 异常ArrayIndexOutofBoundsException

 @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 ------------------- --------------------------- Thread [< 3> main](暂停(异常ArrayIndexOutOfBoundsException)) ListView.layoutChildren()line: 1686 LineView:ViewView(AbsListView).onLayout(boolean,int,int,int,int)行:1224 ListView(View).layout(int,int,int,int)line:6886 LinearLayout.setChildFrame(View, int,int,int)line:1119 LinearLayout.layoutVertical()line:998 LinearLayout.onLayout(boolean,int,int,int,int)line:918 LinearLayout(View).layout(int (int,int,int)行:6886 LineLayout.onLayout(boolean,int,int,int,int)line:333 LinearLayout。 setLayout.onLayout(boolean,int,int,int,int)line:918 LinearLayout(View).layout()查看全文相关信息:LinearLayout.layoutVertical()线:998 LinearLayout.onLayout int,int,int,int)line Phone:6886 PhoneWindow $ DecorView(FrameLayout).onLayout(boolean,int,int,int,int)行:333 PhoneWindow $ DecorView(View).layout(int,int,int, int)行:6886 ViewRoot.performTraversals()line:996 ViewRoot.handleMessage(Message)line:1633 ViewRoot(Handler).dispatchMessage(Message)line:99方法.invokeNative(Object,Object [],Class,Class [],Class,int,boolean)line:不可用[native方法] Method.invoke(对象,对象...)线:521 ZygoteInit $ MethodAndArgsCaller.run()线:862 ZygoteInit.main(字符串[])线:620 NativeStart.main(字符串[])线:不可用[本机方法]

回答

1

我会检查你所得到的是“位置”和比较,为您的项目数组的大小...因为异常说:ArrayIndexOutOfBoundsException异常

+0

我检查。通常情况下,阵列中有5个项目,“位置”不会像预期的那样高于4。通常会在'Position = 4'迭代中发生崩溃,但并非总是如此。 – Frac 2010-09-21 14:32:22