WorldWindJava icon indicating copy to clipboard operation
WorldWindJava copied to clipboard

InstantiationException on .newInstance() method

Open NavneetDhiman20 opened this issue 7 years ago • 1 comments

Description In the world Wind Java Application, whenever i run the ApplicationTemplate Class, it runs well but when i create my own class to create a new application with the same methods, it gives me Instantiation Exception everytime. It is like this java.lang.InstantiationException: gov.nasa.worldwindx.examples.ApplicationTemplate1$ApppFrame at java.lang.Class.newInstance(Class.java:427) at gov.nasa.worldwindx.examples.ApplicationTemplate1.start(ApplicationTemplate1.java:416) at gov.nasa.worldwindx.examples.ApplicationTemplate1.main(ApplicationTemplate1.java:444) Caused by: java.lang.NoSuchMethodException: gov.nasa.worldwindx.examples.ApplicationTemplate1$ApppFrame.() at java.lang.Class.getConstructor0(Class.java:3082) at java.lang.Class.newInstance(Class.java:412)

and I have googled a lot but cannot find a perfect solution to it and the lines at which I am getting the Exception is "AppFrame frame = (AppFrame) appFrameClass.newInstance();" it is not able to create a new instance of the class which is being passed in the appFrameClass.

Expected behavior: the code runs without any exception so that i can complete my application

Actual behavior: getting a runtime Exception that is InstantiationException

Operating System and Version

I am using Ubuntu 14.04 LTS and the java version which i am using is "1.8.0_151"

NavneetDhiman20 avatar Jan 30 '18 11:01 NavneetDhiman20

I haven't tried to use the latest version of Worldwind with a version of JDK 8. I encountered this issue using WorldWind 2.2 with JDK 11 and higher on Windows. So not the same setup but my solution was to add exports for the basic java language modules.

--add-exports=java.base/java.lang=ALL-UNNAMED --add-exports=java.desktop/sun.awt=ALL-UNNAMED --add-exports=java.desktop/sun.java2d=ALL-UNNAMED

When running from the IDE, such as NetBeans you can add it to your default run configuration: image

I hope this helps people in the future.

Birdasaur avatar Aug 10 '24 12:08 Birdasaur