Note that there are some explanatory texts on larger screens.

plurals
  1. POException : java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
    primarykey
    data
    text
    <p>I'm trying to instantiate a Java bean, however it throws </p> <pre><code>java.lang.IndexOutOfBoundsException: Index: 0, Size: 0 at java.util.ArrayList.rangeCheck(ArrayList.java:604) at java.util.ArrayList.get(ArrayList.java:382) at com.application.jsf.BooksTable.getLastId(BooksTable.java:54) at com.application.jsf.BooksManager.&lt;init&gt;(BooksManager.java:24) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:525) at java.lang.Class.newInstance0(Class.java:374) at java.lang.Class.newInstance(Class.java:327) at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:188) ... 55 more </code></pre> <p>Here's the relevant code of <code>BooksManager</code> class:</p> <pre><code>private BooksTable booksTable; private BookGenerator bookGenerator; public BooksManager() { booksTable = new BooksTable(); bookGenerator = new BookGenerator(booksTable.getLastId()); } </code></pre> <p>And the <code>BooksTable</code> class:</p> <pre><code>private ArrayList&lt;BookBean&gt; booksList; private int BOOKS_ON_PAGE = 10; BooksTable(){ this.booksList = new ArrayList&lt;BookBean&gt;(); } public int getLastId(){ if(this.booksList == null){ return -1; } return this.booksList.get(this.booksList.size()).getBookId(); } </code></pre> <p>How is this caused and how can I solve it?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload