exception - index out of bounds in jsp and servlet -


type exception report

message java.lang.indexoutofboundsexception: index: 0, size: 0

description server encountered internal error prevented fulfilling request.

root cause

  java.lang.indexoutofboundsexception: index: 0, size: 0 java.util.arraylist.rangecheck(unknown source) java.util.arraylist.get(unknown source) com.ncr.usedetails.displaydetails.<init>(displaydetails.java:20) org.apache.jsp.success_jsp._jspservice(success_jsp.java:72) org.apache.jasper.runtime.httpjspbase.service(httpjspbase.java:70) javax.servlet.http.httpservlet.service(httpservlet.java:731) org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:439) org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:395) org.apache.jasper.servlet.jspservlet.service(jspservlet.java:339) javax.servlet.http.httpservlet.service(httpservlet.java:731) org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) com.ncr.registration.putdetails.dopost(putdetails.java:81) javax.servlet.http.httpservlet.service(httpservlet.java:650) javax.servlet.http.httpservlet.service(httpservlet.java:731) org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) 

what causing error , how resolve it?

there form(jsp file) has entries ,the servlet(let call a) gets these entries stores them in database.the servlet(a) passes these entries arraylist stores them(i.e. have defined arraylist outside dopost() , used reference variable inside dopost() value of these entries in arraylist).i have defined method outside dopost() has return type of list , returns arraylist.

in class(let call b) import servlet class , use method defined in servlet class arraylist.i store arraylist in new list object.using reference capture value of indexes want inside strings(this inside constructor of class b i.e. entire process of storing arraylist of class in list done inside constructor of class b ).i have method inside class b gets value of arraylist index 0 , stores in string.now use class(b) inside jsp importing inside <%@ %> , creating it's object inside<% %> , calling method gets value of index 0 of arraylist. store value of object.method() inside string variable. , print variable hello! <%=variable %>. there no errors(compile time errors) in code.

(p.s not post code here because lengthy.)

the class display details:- package com.ncr.usedetails;

 import java.util.*;    import com.ncr.registration.putdetails;     public class displaydetails     {      private string fname,lname,uname,pword;     putdetails putdetails=new putdetails();     list<string> catchinglist=new arraylist<string>();     public displaydetails()     {      catchinglist=putdetails.getlistdetails();        fname=catchinglist.get(0);       lname=catchinglist.get(1);       uname=catchinglist.get(2);       pword=catchinglist.get(3);        }      public string getfirstname()    {        return fname;       }   } 

check this

com.ncr.usedetails.displaydetails.<init>(displaydetails.java:20) 

line number 20 in displaydetails.java, there must array fetch operation taking place.

the array seems empty. try sysout (or log, if have logging enabled) , check value on server console/log file.

edit: in response of comments , code posted, try

 public displaydetails()     {     catchinglist=putdetails.getlistdetails();     // print size of list, check on server console.     system.out.println(catchinglist.size());      // because expecting 4 elements, check beforehand if have indeed 4 elements.     if(catchinglist.size() >= 4) {       fname=catchinglist.get(0);       lname=catchinglist.get(1);       uname=catchinglist.get(2);       pword=catchinglist.get(3);     }else {      // not getting 4 elements, there in array list. lets print on server console.       system.out.println(catchinglist);     } } 

this 1 way debug, on whether getting expected.


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -