我是一個非常綠色的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(字符串[])線:不可用[本機方法]
我檢查。通常情況下,陣列中有5個項目,「位置」不會像預期的那樣高於4。通常會在'Position = 4'迭代中發生崩潰,但並非總是如此。 – Frac 2010-09-21 14:32:22