NoSuchElementException错误500

时间:2017-07-26 10:34:02

标签: java ajax eclipse jsp stack-trace

我在VM(ubuntu 14)上部署我的spring项目,当我使用执行ajax调用的按钮时,它在堆栈中给出了错误500,NoSuchElementException指向迭代器。

我的应用程序在eclipse上工作正常,并且在我的VM中部署时,所以我将VM(所有工作正常)导出到客户端计算机,但仍然给出错误500.

这是跟踪:

HTTP Status 500 - An exception occurred processing JSP page /executeComparison.jsp at line 7

type Exception report

message An exception occurred processing JSP page /executeComparison.jsp at 
line 7

description The server encountered an internal error that prevented it from 
fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page 
/executeComparison.jsp at 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 The full stack trace of the root cause is available in the Apache 
Tomcat/7.0.53 logs.

Apache Tomcat/7.0.53

我不认为迭代器或java代码在eclipse和我的计算机上的VM中工作得很好,当我在客户端计算机上使用相同的VM时,错误是存在的, ajax调用失败并给出以下错误

jquery-1.11.0.min.js:4 GET 
https://193.169.100.12:8443/DMX.v.3.10/executeComparison.jsp?
rand=0.9844812755765802 500 (Internal Server Error)

这是ajax调用:

        function evaluateDelta() {
        var rand = Math.random();
        $.ajax({
            url: "executeComparison.jsp",
            dataType: 'text',
            data: { rand: rand },
            success: function (data) {
                console.log("got the difference");
                displayDelta();
            }
        });

    }

这是jsp页面:

 <%@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();
 %>

当我查看日志时,我发现&#34;我正在比较打印的&#34;这意味着ajax进入jsp但jsp在下一行失败,如堆栈跟踪所示。

最后这里是迭代器指向堆栈的函数(syso中的那个函数&#34; System.out.println(&#34; \ r \ n \ r \ n ------ ------命令&#34; + it.next()+&#34; \ r \ n \ r \ n&#34;);&#34;:

 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> it = 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);
                            for (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();
} finally {

    if (in != null) {
        try {
            in.close();
        } catch (IOException e) {
        }
    }
    if (in2 != null) {
        try {
            in2.close();
        } catch (IOException e) {

        }
    }
}
}

任何想法都是这个错误可以来自我搜索所有论坛和网站我知道但是徒劳。

非常感谢。

1 个答案:

答案 0 :(得分:0)

在致电Iterator.hasNext()之前,您必须先检查是否Iterator.next()。即使代码在某些环境中工作,代码中也可能存在NoSuchElementException。

另见: https://docs.oracle.com/javase/8/docs/api/java/util/Iterator.html