gpt4 book ai didi

android - 发生 ArrayIndexOutOfBoundsException

转载 作者:行者123 更新时间:2023-11-29 18:04:40 26 4
gpt4 key购买 nike

我正在使用 BaseAdapter:

public class MyAdapter extends BaseAdapter{
private final LayoutInflater mInflater;
private final String[] mItems;
private final String[] mClasses;
private final Drawable[] mIcons;
private final Integer mii;
public MyAdapter(Activity c, String[] objects, Drawable[] dricons, String[] classes, Integer ii) {
mInflater = c.getLayoutInflater();
mClasses = classes;
mItems = objects;
mIcons = dricons;
mii = ii;
}
public int getCount() {
return mItems.length;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (convertView == null) {
convertView = mInflater.inflate(R.layout.listitem, null);
}
((TextView)convertView).setCompoundDrawablesWithIntrinsicBounds( mIcons[position], null, null, null);
((TextView)convertView).setText(mItems[position]);
((TextView)convertView).setTag(mClasses[position]);
return convertView;
}
@Override
public Object getItem(int position) {
return mItems[position];
// return mClasses[position];
}
@Override
public long getItemId(int position) {
return position;
}

}

当我向下滚动我的 ListView 时,应用程序会在滚动一半列表后抛出 suxh 异常。

12-26 19:39:36.020: E/AndroidRuntime(11800): FATAL EXCEPTION: main
12-26 19:39:36.020: E/AndroidRuntime(11800): java.lang.ArrayIndexOutOfBoundsException
12-26 19:39:36.020: E/AndroidRuntime(11800): at com.tsysv.widgetchanger.MyAdapter.getView(MyAdapter.java:38)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.widget.AbsListView.obtainView(AbsListView.java:1294)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.widget.ListView.makeAndAddView(ListView.java:1727)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.widget.ListView.fillDown(ListView.java:652)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.widget.ListView.fillGap(ListView.java:623)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.widget.AbsListView.trackMotionScroll(AbsListView.java:2944)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.widget.AbsListView.onTouchEvent(AbsListView.java:2065)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.widget.ListView.onTouchEvent(ListView.java:3315)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.view.View.dispatchTouchEvent(View.java:3765)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:905)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:944)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:944)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:944)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:944)
12-26 19:39:36.020: E/AndroidRuntime(11800): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1701)
12-26 19:39:36.020: E/AndroidRuntime(11800): at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1116)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.app.Activity.dispatchTouchEvent(Activity.java:2093)
12-26 19:39:36.020: E/AndroidRuntime(11800): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1685)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.view.ViewRoot.handleMessage(ViewRoot.java:1802)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.os.Handler.dispatchMessage(Handler.java:99)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.os.Looper.loop(Looper.java:144)
12-26 19:39:36.020: E/AndroidRuntime(11800): at android.app.ActivityThread.main(ActivityThread.java:4937)
12-26 19:39:36.020: E/AndroidRuntime(11800): at java.lang.reflect.Method.invokeNative(Native Method)
12-26 19:39:36.020: E/AndroidRuntime(11800): at java.lang.reflect.Method.invoke(Method.java:521)
12-26 19:39:36.020: E/AndroidRuntime(11800): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
12-26 19:39:36.020: E/AndroidRuntime(11800): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
12-26 19:39:36.020: E/AndroidRuntime(11800): at dalvik.system.NativeStart.main(Native Method)

有什么问题?

最佳答案

问题是当您调用构造函数时,您没有向适配器提供两个相同长度的数组。

关于android - 发生 ArrayIndexOutOfBoundsException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14042809/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com