0

目前我从代码运行中得到以下输出

Caused by: java.lang.NullPointerException
    at com.gargoylesoftware.htmlunit.html.HtmlScript$2.execute(HtmlScript.java:227)
    at com.gargoylesoftware.htmlunit.html.HtmlScript.onAllChildrenAddedToPage(HtmlScript.java:256)
    at com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoDOMBuilder.endElement(HtmlUnitNekoDOMBuilder.java:560)
    at org.apache.xerces.parsers.AbstractSAXParser.endElement(Unknown Source)
    at com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoDOMBuilder.endElement(HtmlUnitNekoDOMBuilder.java:514)
    at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.callEndElement(HTMLTagBalancer.java:1192)
    at net.sourceforge.htmlunit.cyberneko.HTMLTagBalancer.endElement(HTMLTagBalancer.java:1132)
    at net.sourceforge.htmlunit.cyberneko.filters.DefaultFilter.endElement(DefaultFilter.java:219)
    at net.sourceforge.htmlunit.cyberneko.filters.NamespaceBinder.endElement(NamespaceBinder.java:312)
    at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scanEndElement(HTMLScanner.java:3189)
    at net.sourceforge.htmlunit.cyberneko.HTMLScanner$ContentScanner.scan(HTMLScanner.java:2114)
    at net.sourceforge.htmlunit.cyberneko.HTMLScanner.scanDocument(HTMLScanner.java:937)
    at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:443)
    at net.sourceforge.htmlunit.cyberneko.HTMLConfiguration.parse(HTMLConfiguration.java:394)
    at org.apache.xerces.parsers.XMLParser.parse(Unknown Source)
    at com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoDOMBuilder.parse(HtmlUnitNekoDOMBuilder.java:760)
    at com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoHtmlParser.parseFragment(HtmlUnitNekoHtmlParser.java:158)
    at com.gargoylesoftware.htmlunit.html.parser.neko.HtmlUnitNekoHtmlParser.parseFragment(HtmlUnitNekoHtmlParser.java:112)
    at com.gargoylesoftware.htmlunit.javascript.host.Element.parseHtmlSnippet(Element.java:868)
    at com.gargoylesoftware.htmlunit.javascript.host.Element.setInnerHTML(Element.java:920)
    at com.gargoylesoftware.htmlunit.javascript.host.html.HTMLElement.setInnerHTML(HTMLElement.java:676)
    at sun.reflect.GeneratedMethodAccessor17.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at net.sourceforge.htmlunit.corejs.javascript.MemberBox.invoke(MemberBox.java:188)
    ... 30 more

以上... 30 more意味着我不知道导致问题的代码行。如何获得完整的堆栈跟踪。

此外,如果它似乎没有运行我的任何 catch 语句printStackTrace,但是如果我使用以下命令关闭日志记录

java.util.logging.Logger.getLogger("com.gargoylesoftware.htmlunit").setLevel(java.util.logging.Level.OFF);

java.util.logging.Logger.getLogger("org.apache.http").setLevel(java.util.logging.Level.OFF);


**Have put in my full code below as suggested by the comments below . Did not put in the actual URL though**

import com.gargoylesoftware.htmlunit.html.*;
import java.io.File;
import com.gargoylesoftware.htmlunit.WebClient;
import com.gargoylesoftware.htmlunit.html.HtmlPage;



public class download_to_send_to_stackoverflow
{
     public static void main(String args[])
     {

      String url = "did not want to include the actual web site ";


      HtmlPage page = null;

      WebClient webClient = new WebClient();
      webClient.getOptions().setRedirectEnabled(true);  
      webClient.getOptions().setJavaScriptEnabled(true);  // tried making false - but didnt work
      webClient.getOptions().setCssEnabled(false);
      webClient.getOptions().setUseInsecureSSL(true);
          webClient.getOptions().setTimeout(30000);
      webClient.setJavaScriptTimeout(30000); //e.g. 50s
      webClient.waitForBackgroundJavaScript(15000) ;   // added 2017/1/24
      webClient.waitForBackgroundJavaScriptStartingBefore(30000) ;   // added 2017/1/24


          try
               {
               page = webClient.getPage( url );
           savePage_just_html(page );  
           }

          catch( Exception e )
               {
               System.out.println( "Exception thrown:----------------------------------------" + e.getMessage() );
               e.printStackTrace();
               }
     }




     protected static String savePage_just_html(HtmlPage page)
     {
          try
          {
            File saveFolder = new File("spool/_");
            page.save(saveFolder);   // this is the line causing the error with limit stack trace
          }



          catch ( Exception e )
          {
               System.out.println( "IOException was thrown: ---------------------------------- " + e.getMessage() );
               e.printStackTrace();
          }


          return "file.html";
     }



}



------------------------------------------------------


  page.save(saveFolder);   above is the problem line.  if I take it out I dont get the limited statcktrace errors but I also dont save the html page - which I want to do

- The question is - why does this line only print a limited stacktrace
4

1 回答 1

2

“Caused by”表示这是一个嵌套异常。

嵌套异常堆栈跟踪中的“... 30 more”意味着这 30 行与主要异常中的相同。

因此,只需查看主堆栈跟踪即可查看这些堆栈帧。


显然,您的异常堆栈跟踪是以抑制(或删除)主要异常堆栈跟踪的方式生成的。这令人费解,但它可能是由您正在使用的单元测试库之一完成的。

深入了解这可能需要您调试生成堆栈跟踪的任何内容,或者编写一个最小的可重现示例,以便其他人可以调试它。

于 2020-08-14T04:43:43.443 回答