java.lang.ArrayIndexOutOfBoundsException:超出范围

java.lang.ArrayIndexOutOfBoundsException: Out of range

这适用于应用 android、运行 Android 工作室、数据库领域和 sql 服务器。我需要帮助

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_list_employee);
    toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
    realm = Realm.getDefaultInstance();
    preferences = getSharedPreferences(PREFS_LOGIN, Context.MODE_PRIVATE);
    recyclerView = findViewById(R.id.recyclerview);
    singleItem = new ArrayList<>();
    RealmResults<MdtmMandoranEmployeeDetail> resultEmployeeDetails = realm.where(MdtmMandoranEmployeeDetail.class)
            .findAll().sort("employeename");
    adapterListPemanen = new AdapterListPemanen(this, singleItem, this);
    initVerticalRecycler();
    for (int i = 0; i < 50; i++) {
        DataPemanen data = realm.where(DataPemanen.class)
                .equalTo("nik", resultEmployeeDetails.get(i).getEmployeeid())
                .findFirst();
        if (data == null) {
            singleItem.add(new MdtmMandoranEmployeeDetail(resultEmployeeDetails.get(i).getMandoranemployeeid(),
                    resultEmployeeDetails.get(i).getEmployeeid(),
                    resultEmployeeDetails.get(i).getEmployeename()));
        }
    }
}

错误日志

E/REALM_JNI: jni: ThrowingException 2, Out of range  in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsResults.cpp line 102(requested: 0 valid: 0), .
    Exception has been thrown: Out of range  in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsResults.cpp line 102(requested: 0 valid: 0)
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.hpi.android.bkm, PID: 16623
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hpi.android.bkm/com.hpi.android.bkm.ui.main.input_pengiriman_hasil_panen.ListEmployeeActivity}: java.lang.ArrayIndexOutOfBoundsException: Out of range  in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsResults.cpp line 102(requested: 0 valid: 0)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2805)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2883)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6523)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)
     Caused by: java.lang.ArrayIndexOutOfBoundsException: Out of range  in /Users/cm/Realm/realm-java/realm/realm-library/src/main/cpp/io_realm_internal_OsResults.cpp line 102(requested: 0 valid: 0)
        at io.realm.internal.OsResults.nativeGetRow(Native Method)
        at io.realm.internal.OsResults.getUncheckedRow(OsResults.java:325)
        at io.realm.OrderedRealmCollectionImpl.get(OrderedRealmCollectionImpl.java:124)
        at io.realm.RealmResults.get(RealmResults.java:62)
        at com.hpi.android.bkm.ui.main.input_pengiriman_hasil_panen.ListEmployeeActivity.onCreate(ListEmployeeActivity.java:64)
        at android.app.Activity.performCreate(Activity.java:7023)
        at android.app.Activity.performCreate(Activity.java:7014)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2758)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2883) 
        at android.app.ActivityThread.-wrap11(Unknown Source:0) 
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1613) 
        at android.os.Handler.dispatchMessage(Handler.java:106) 
        at android.os.Looper.loop(Looper.java:164) 
        at android.app.ActivityThread.main(ActivityThread.java:6523) 
        at java.lang.reflect.Method.invoke(Native Method) 
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) 
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:857)

for循环应该是,

for (int i = 0; i < resultEmployeeDetails.size(); i++) {
  ....
  ....
}