• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Rob Spoor
  • Henry Wong
  • Liutauras Vilda
Saloon Keepers:
  • Tim Moores
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh
  • Jj Roberts

ExceptionInInitializerError

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm trying to follow some HtmlUnit tutorials, but no matter which example code I try, I always receive same error message.




Error:
Exception in thread "main" java.lang.ExceptionInInitializerError
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Unknown Source)
at java.base/java.lang.reflect.ReflectAccess.newInstance(Unknown Source)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(Unknown Source)
at java.base/java.lang.Class.newInstance(Unknown Source)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.configureClass(JavaScriptEngine.java:596)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.init(JavaScriptEngine.java:290)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.lambda$initialize$0(JavaScriptEngine.java:183)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:619)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:537)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.initialize(JavaScriptEngine.java:181)
at com.gargoylesoftware.htmlunit.WebClient.initialize(WebClient.java:1229)
at com.gargoylesoftware.htmlunit.WebWindowImpl.setEnclosedPage(WebWindowImpl.java:139)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:294)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:216)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:648)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:470)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:382)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:539)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:520)
at hello.HelloWorld.main(HelloWorld.java:20)
Caused by: java.nio.charset.UnsupportedCharsetException: big5
at java.base/java.nio.charset.Charset.forName(Unknown Source)
at com.gargoylesoftware.htmlunit.javascript.host.TextDecoder.<clinit>(TextDecoder.java:60)
... 23 more

Anyone have any ideas?
 
Marshal
Posts: 72407
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Beware of catching plain simple Exception; it is too non‑specific. Find out which sort of exception you should expect and catch that.
 
Campbell Ritchie
Marshal
Posts: 72407
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for giving us lots of information to work with

Sorry: only posted half a post. I was going to say the following:-

Where is the exception occurring? I can't see any initialisers. It isn't occurring at line 20, but in some of the code you haven't shown us. It is probably occurring in one of the classes you imported. Are the line numbers you showed the same as those in the stack trace?

Your code isn't quote indented correctly; look at the lines after 23. Please break up the long lines, well line 19, which is difficult to read.
 
Marshal
Posts: 26458
81
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Near the bottom:

Caused by: java.nio.charset.UnsupportedCharsetException: big5



I see that it isn't you which is using the Big5 charset. So it must be the website you're connecting to. A URL starting with newyork.craigslist.org doesn't seem to me to be likely to have a lot of Traditional Chinese content, but I can see from the stack trace that there's JavaScript processing going on. Maybe there's some Taiwanese ads on the page you're downloading? Still seems a bit mysterious to me.
 
Alex Alvez
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here is another piece of code with proper line numbers that produces the same error message.




Error:

Exception in thread "main" java.lang.ExceptionInInitializerError
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Unknown Source)
at java.base/java.lang.reflect.ReflectAccess.newInstance(Unknown Source)
at java.base/jdk.internal.reflect.ReflectionFactory.newInstance(Unknown Source)
at java.base/java.lang.Class.newInstance(Unknown Source)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.configureClass(JavaScriptEngine.java:596)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.init(JavaScriptEngine.java:290)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.lambda$initialize$0(JavaScriptEngine.java:183)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:619)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:537)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.initialize(JavaScriptEngine.java:181)
at com.gargoylesoftware.htmlunit.WebClient.initialize(WebClient.java:1229)
at com.gargoylesoftware.htmlunit.WebWindowImpl.setEnclosedPage(WebWindowImpl.java:139)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createHtmlPage(DefaultPageCreator.java:294)
at com.gargoylesoftware.htmlunit.DefaultPageCreator.createPage(DefaultPageCreator.java:216)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:648)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:470)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:382)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:539)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:520)
at hello.HelloWorld.main(HelloWorld.java:15)
Caused by: java.nio.charset.UnsupportedCharsetException: big5
at java.base/java.nio.charset.Charset.forName(Unknown Source)
at com.gargoylesoftware.htmlunit.javascript.host.TextDecoder.<clinit>(TextDecoder.java:60)
... 23 more


 
Campbell Ritchie
Marshal
Posts: 72407
315
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the big5 charset? Look here. It would appear something is trying to use that charset but can't. The problem appears not to be in your code. Don't know any more: sorry.
 
Thank you my well lotioned goddess! Here, have my favorite tiny ad!
SKIP - a book about connecting industrious people with elderly land owners
https://coderanch.com/t/skip-book
reply
    Bookmark Topic Watch Topic
  • New Topic