java - Error 500 with NoSuchElementException -
i'm deploying spring project on vm (ubuntu 14) , when use button perform ajax call gives error500 in stack nosuchelementexception pointed iterator.
my app work fine on eclipse , when deploying in vm, exported vm (where work fine) client computer, still giving error 500.
here trace:
http status 500 - exception occurred processing jsp page /executecomparison.jsp @ line 7 type exception report message exception occurred processing jsp page /executecomparison.jsp @ line 7 description server encountered internal error prevented fulfilling request. exception org.apache.jasper.jasperexception: exception occurred processing jsp page /executecomparison.jsp @ line 7 4: 5: <% 6: system.out.println("i'm comparing"); 7: computedifference.printdiffs(computedifference.getalldiffs("p1", "p2")); 8: string data = "active"; 9: out.print(data); 10: out.flush(); stacktrace: org.apache.jasper.servlet.jspservletwrapper.handlejspexception(jspservletwrapper.java:568) org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:470) org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:390) org.apache.jasper.servlet.jspservlet.service(jspservlet.java:334) javax.servlet.http.httpservlet.service(httpservlet.java:727) org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) root cause java.util.nosuchelementexception java.util.arraylist$itr.next(arraylist.java:834) comparator.computedifference.compare(computedifference.java:212) comparator.computedifference.getalldiffs(computedifference.java:29) org.apache.jsp.executecomparison_jsp._jspservice(executecomparison_jsp.java:70) org.apache.jasper.runtime.httpjspbase.service(httpjspbase.java:70) javax.servlet.http.httpservlet.service(httpservlet.java:727) org.apache.jasper.servlet.jspservletwrapper.service(jspservletwrapper.java:432) org.apache.jasper.servlet.jspservlet.servicejspfile(jspservlet.java:390) org.apache.jasper.servlet.jspservlet.service(jspservlet.java:334) javax.servlet.http.httpservlet.service(httpservlet.java:727) org.apache.tomcat.websocket.server.wsfilter.dofilter(wsfilter.java:52) note full stack trace of root cause available in apache tomcat/7.0.53 logs. apache tomcat/7.0.53 i dont think iterator or java code seen working fine on eclipse , in vm in computer, bug there when i'm using same vm on client computer, ajax call fail , give following error
jquery-1.11.0.min.js:4 https://193.169.100.12:8443/dmx.v.3.10/executecomparison.jsp? rand=0.9844812755765802 500 (internal server error) here ajax call:
function evaluatedelta() { var rand = math.random(); $.ajax({ url: "executecomparison.jsp", datatype: 'text', data: { rand: rand }, success: function (data) { console.log("got difference"); displaydelta(); } }); } and here jsp page:
<%@page import="java.util.*"%> <%@page import="comparator.computedifference"%> <% system.out.println("i'm comparing"); computedifference.printdiffs(computedifference.getalldiffs("p1", "p2")); string data = "active"; out.print(data); out.flush(); %> when i'm checking logs found "i'm comparing printed" means ajax went jsp jsp failed on next line shown on stack trace.
and here function iterator pointed on stack (the 1 in syso " system.out.println("\r\n\r\n------------ command "+it.next()+"\r\n\r\n"); ":
static public void compare (string filename1,string filename2) throws ioexception{ string filepath1="c:/users/mike/desktop/"+filename1+".txt"; string filepath2="c:/users/mike/desktop/"+filename2+".txt"; bufferedreader in = null; bufferedreader inn=null; bufferedreader in2=null; bufferedreader in2n=null; string line = "", line2= ""; arraylist<string> commands=computedifference.getcommands(filepath1); iterator<string> = commands.iterator(); boolean command=true; try { in = new bufferedreader(new filereader(filepath1)); inn = new bufferedreader(new filereader(filepath1)); inn.readline(); in2= new bufferedreader(new filereader(filepath2)); in2n= new bufferedreader(new filereader(filepath2)); in2n.readline(); file file = new file("c:/users/mike/desktop/command1.txt"); file file1 = new file("c:/users/mike/desktop/command2.txt"); file filediff = new file("c:/users/mike/desktop/commanddiff.txt"); printstream printstreamtofile = new printstream(file); printstream printstreamtofile1 = new printstream(file1); printstream printstreamtofilediff = new printstream(filediff); int i=0; while ((line = in.readline()) != null ) { string next=inn.readline(); system.setout(printstreamtofile); system.out.println(line); if(next != null && next.contains("#")){ command=true; while (command == true && (line2 = in2.readline()) != null) { string next2=in2n.readline(); system.setout(printstreamtofile1); system.out.println(line2); if(next2 != null && next2.contains("#")){ system.setout(printstreamtofilediff); if(i!=0){ system.out.println("\r\n\r\n------------ command "+it.next()+"\r\n\r\n"); list<string> original = filetolines("command1"); list<string> revised = filetolines("command2"); system.setout(printstreamtofilediff); patch<string> patch = diffutils.diff(original, revised); (delta<string> delta: patch.getdeltas()) { system.setout(printstreamtofilediff); system.out.println(delta); } } else{ i++; it.next(); } printstreamtofile1.close(); file1.delete(); file1.createnewfile(); printstreamtofile1=new printstream(file1); command=false; } } printstreamtofile.close(); file.delete(); file.createnewfile(); printstreamtofile=new printstream(file); } } system.setout(applicationconstant.console); } catch (ioexception e) { e.printstacktrace(); } { if (in != null) { try { in.close(); } catch (ioexception e) { } } if (in2 != null) { try { in2.close(); } catch (ioexception e) { } } } } any idea error can came searched forums , websites know in vain.
many thanks.
you must check if iterator.hasnext() before calling iterator.next(). there possibility of nosuchelementexception in code if working on environments.
see also: https://docs.oracle.com/javase/8/docs/api/java/util/iterator.html
Comments
Post a Comment