如何解决问题'ArrayIndexOutOfBoundsException'?

时间:2012-03-05 08:28:07

标签: android arrays indexing indexoutofboundsexception

这是logcat中发生的错误,任何人都能说出这是什么意思?

private int getDayIdxInTrip(int position) {
DayTagItem item = null;
    Integer dayIdx = -1;
    try {
        if (mTripItems.get(position).mViewType == TripDetailAdapter.DAYTAG_TYPE) {
            item = (DayTagItem) mTripItems.get(position);
        } else {
            Logger.e(TAG, "Wrong view type found on position == "
                    + position);
            position--;
            return getDayIdxInTrip(position);
        }
        dayIdx = Integer
                .parseInt(item.mDayIdx != null
                        && !item.mDayIdx.trim().equals("")
                        && !item.mDayIdx.trim().equalsIgnoreCase("null") ? item.mDayIdx
                        : "0");
    } catch (Exception e) {
        Logger.e(TAG, "getDayIdxInTrip() error!"+e.getMessage());
    }
    Logger.i(TAG,"returned"+dayIdx);
    return dayIdx;
}
  

03-05 16:19:10.092:E / AndroidRuntime(29009):java.lang.ArrayIndexOutOfBoundsException      03-05 16:19:10.092:E / AndroidRuntime(29009):在android.widget.AbsListView $ RecycleBin.addScrapView(AbsListView.java:4180)   03-05 16:19:10.092:E / AndroidRuntime(29009):在android.widget.AbsListView.trackMotionScroll(AbsListView.java:3017)   03-05 16:19:10.092:E / AndroidRuntime(29009):在android.widget.AbsListView.onTouchEvent(AbsListView.java:2117)   03-05 16:19:10.092:E / AndroidRuntime(29009):在android.widget.ListView.onTouchEvent(ListView.java:3377)   03-05 16:19:10.092:E / AndroidRuntime(29009):在android.view.View.dispatchTouchEvent(View.java:3766)   03-05 16:19:10.092:E / AndroidRuntime(29009):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:897)   03-05 16:19:10.092:E / AndroidRuntime(29009):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)   03-05 16:19:10.092:E / AndroidRuntime(29009):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)   03-05 16:19:10.092:E / AndroidRuntime(29009):在android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:936)   03-05 16:19:10.092:E / AndroidRuntime(29009):at com.android.internal.policy.impl.PhoneWindow $ DecorView.superDispatchTouchEvent(PhoneWindow.java:1746)   03-05 16:19:10.092:E / AndroidRuntime(29009):at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1117)   03-05 16:19:10.092:E / AndroidRuntime(29009):在android.app.Activity.dispatchTouchEvent(Activity.java:2092)   03-05 16:19:10.092:E / AndroidRuntime(29009):at com.android.internal.policy.impl.PhoneWindow $ DecorView.dispatchTouchEvent(PhoneWindow.java:1730)   03-05 16:19:10.092:E / AndroidRuntime(29009):在android.view.ViewRoot.handleMessage(ViewRoot.java:1794)   03-05 16:19:10.092:E / AndroidRuntime(29009):在android.os.Handler.dispatchMessage(Handler.java:99)   03-05 16:19:10.092:E / AndroidRuntime(29009):在android.os.Looper.loop(Looper.java:143)   03-05 16:19:10.092:E / AndroidRuntime(29009):在android.app.ActivityThread.main(ActivityThread.java:4701)   03-05 16:19:10.092:E / AndroidRuntime(29009):at java.lang.reflect.Method.invokeNative(Native Method)   03-05 16:19:10.092:E / AndroidRuntime(29009):at java.lang.reflect.Method.invoke(Method.java:521)   03-05 16:19:10.092:E / AndroidRuntime(29009):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:860)   03-05 16:19:10.092:E / AndroidRuntime(29009):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)   03-05 16:19:10.092:E / AndroidRuntime(29009):at dalvik.system.NativeStart.main(Native Method)

1 个答案:

答案 0 :(得分:0)

来自文档:

  

抛出表示已使用非法访问数组   指数。该指数为负数或大于或等于   数组的大小。

示例:

int myArray = new int[10];
myArray[11] = 123;

没有代码,我们无能为力。