sublist index out of bound exception

后端 未结 3 1696
无人共我
无人共我 2021-01-21 14:45

Whenever I am running my xhtml. It is giving me the following exception. The value of statusindex object is 5. I am using JQuery for lazy scrolling,so when my xhml page getMoreS

相关标签:
3条回答
  • 2021-01-21 15:04

    List.subList()'s documentation is very clear:

    Throws: IndexOutOfBoundsException - for an illegal endpoint index value (fromIndex < 0 || toIndex > size || fromIndex > toIndex)

    In your case, toIndex > size:

    java.lang.IndexOutOfBoundsException: toIndex = 30
    
    0 讨论(0)
  • 2021-01-21 15:27

    The message says that toIndex is 30. That means that statusindex is not 5, as you believe it is, but 25:

    java.lang.IndexOutOfBoundsException: toIndex = 30
    

    Side note, you should use named parameters in your queries instead of String concatenation to pass parameters. Your code is vulnerable to SQL injection attacks. It will also fail if the email address happens to contain a single quote.

    0 讨论(0)
  • 2021-01-21 15:28

    results = results.subList(index,index+5);

    So it would do:

    results.subList(25,30); if passed 25, hence the error.

    0 讨论(0)
提交回复
热议问题