http://docs.oracle.com/javafx/2/text/NeonSign.java.html
when I try to run the neonsign java example from oracle in intelliJ this is my error:
Exception in thread "main" java.lang.ClassNotFoundException: NeonSign
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:122)
https://docs.oracle.com/javase/7/docs/api/java/lang/ClassNotFoundException.html
public class ClassNotFoundException
extends ReflectiveOperationException
Thrown when an application tries to load in a class through its string name using:
The forName method in class Class.
The findSystemClass method in class ClassLoader .
The loadClass method in class ClassLoader.
but no definition for the class with the specified name could be found.
As of release 1.4, this exception has been retrofitted to conform to the general purpose exception-chaining mechanism. The "optional exception that was raised while loading the class" that may be provided at construction time and accessed via the getException() method is now known as the cause, and may be accessed via the Throwable.getCause() method, as well as the aforementioned "legacy method."
I believe this usually happens when you do not have the Library/jar in question added, and have to add it to your current project.
Please make sure you are Using Java 8 (1.8) or you have JavaFX added to your project.
In this case, after looking through the example I found this line of code
scene.getStylesheets().add(NeonSign.class.getResource("brickStyle.css").toExternalForm());
I wonder if the issue is because it's trying to get a resource that doesn't exist (brickStyle.css). If you remove this line, does the error persist?
This might also have to do with you not having JavaFX in your project.
Also, additional reading.
How do I resolve this Java Class not found exception?
Just to add, depending on if IDEA gives you a sample of an FX application, but Netbeans has a FXApplication project with "FXMainClass" that has a built in small example.
Good luck.
Related
Hi I try to execute my Spring application with dependency of JWT package and I found this error:
Caused by: java.lang.IllegalAccessError: tried to access method sun.security.rsa.RSAPublicKeyImpl.<init>([B)V from class com.agospass.OAuth2ResourceServerConfig
at com.agospass.OAuth2ResourceServerConfig.accessTokenConverter(OAuth2ResourceServerConfig.java:87)
at com.agospass.OAuth2ResourceServerConfig$$EnhancerBySpringCGLIB$$e9e14628.CGLIB$accessTokenConverter$3(<generated>)
at com.agospass.OAuth2ResourceServerConfig$$EnhancerBySpringCGLIB$$e9e14628$$FastClassBySpringCGLIB$$e622f9ed.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
at com.agospass.OAuth2ResourceServerConfig$$EnhancerBySpringCGLIB$$e9e14628.accessTokenConverter(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
... 50 common frames omitted
My jdk version 8u241 and Maven 3.8.1
someone who can help me solve this problem or replace the dependency?
public class IllegalAccessError extends IncompatibleClassChangeError
Thrown if an application attempts to access or modify a field, or to
call a method that it does not have access to. Normally, this error is
caught by the compiler; this error can only occur at run time if the
definition of a class has incompatibly changed.
https://docs.oracle.com/javase/8/docs/api/java/lang/IllegalAccessError.html
Edited: For JDK 11
https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/IllegalAccessError.html
Certainly, your class OAuth2ResourceServerConfig's method accessTokenConverter is trying to invoke the method from a different class available in different jar than one it compile with. This behaviour is often seen when the same class (with same package) is present in different jars with difference in the accessibility of fields/methods.
To put it simply, one can say that at compile time your code has access to public method of class available in jar one but at runtime, thanks to classloader, your code is trying to access the private method of same class available in jar two.
You can look for RSAPublicKeyImpl class inside the dependencies present on the classpath and update/adjust the dependencies accordingly to get rid of the issue.
I have an Android project in Android Studio;
And I create a java-library module (the steps is: File -> New -> New Module -> Java library);
I add a third library by gradle, such as: "compile 'com.squareup.okhttp3:okhttp:3.9.1'";
then, I use the OkHttpClient in my Main class's main method, It ok, compile successfully.
But I run the Main method, the console print errors:
```
Exception in thread "main" java.lang.NoClassDefFoundError: okhttp3/OkHttpClient
at com.zhang.anan.mylib.myClass.main(myClass.java:12)
Caused by: java.lang.ClassNotFoundException: okhttp3.OkHttpClient
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
```
As per the Oracle documentation, ClassNotFoundException is thrown following the failure of a class loading call, using its string name, as per below:
The Class.forName method
The ClassLoader.findSystemClass method
The ClassLoader.loadClass method
In other words, it means that one particular Java class was not found or could not be loaded at runtime from your application current context class loader.
How to resolve
Identify the caller :From the stack trace just before the Class.forName() or ClassLoader.loadClass() calls. This will help you understand if your application code is at fault vs. a third party API.
Determine if your application code is not packaged properly e.g. missing JAR file(s) from your classpath.
If the missing Java class is not from your application code, then identify if it belongs to a third party API you are using as per of your Java application. Once you identify it, you will need to add the missing JAR file(s) to your runtime classpath or web application WAR/EAR file.
I developed a web service in java that makes addition, subtraction, division and multiplication. Then, I created a class named CallCalc in another project named CallCalculator. I wrote some code in the class to call the web service. When I run the class CallCalc with parameters in eclipse, it returns to me the correct result, but when I run the class CallCalc with parameters in cmd, it throws an exception like;
Exception in thread "main" java.lang.NoClassDefFoundError: com\example\ws\calculator\CalculatorSEI
at CallCalc.main<CallCalc.java:32>
Caused by: java.lang.ClassNotFoundException: com.example.ws.calculator.CalculatorSEI
at java.net.URLClassLoader.findClass<Unknown Source>
at java.lang.ClassLoader.loadClass<Unknown Source>
at sun.misc.Launcher$AppClassLoader.loadClass<Unknown Source>
at java.lang.ClassLoader.loadClass<Unknown Source>
... 1 more
I searched for a long time, tried different ways but could not correct it and I'm really confused. Maybe its answer is very simple, forgive me for that.
Does anybody have an idea about how to solve it? (I can post the necessary code block if you need)
Is you project using maven? If so.. Do you have a dependency to the "SEI module" where CalculatorSEI is in?
A NoClassDefFoundError occurs when you're using a class that is unknown at runtime hence you probably don't have a dependency to it.
Im running a debian java server that needs to send and receive objects of type EventObject and PostObject (e.g serializable). These have been placed in a .jar file SharedModels.jar and are used both in client and server.
On the windows installation (Eclipse), using
import Models.EventObject;
import Models.PostObject;
works fine (including external Jar through Eclipse).
It compiles fine, but when the method is called on the server , the server doesn't recognize the class anymore. This is the output:
Exception in thread "Thread-0" java.lang.NoClassDefFoundError: Models/PostObject
at server.Database.getPosts(Database.java:101)
at server.ServerThread.run(ServerThread.java:47)
Caused by: java.lang.ClassNotFoundException: Models.PostObject
at java.net.URLClassLoader$1.run(URLClassLoader.java:372)
at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 2 more
I've understood this is because JVM does recognize the class at compiletime but not during runtime.. OR something is wrong with classpath. Does the name of the actual .jar need to have any naming to fid the package contained within? What do I need to do to fix this?
If your Models/PostObject is a class from some jar, then make sure that the class is included in exported jar/war (simply open it with tool like 7zip and manually confirm that the needed class is there).
How to create a jar with external libraries included in Eclipse?
This is thrown when at compile time the required classes are present , but at run time the classes are changed or removed or class's static initializes threw exceptions. It means the class which is getting loaded is present in classpath , but one of the classes which are required by this class , are either removed or failed to load by compiler .So you should see the classes which are dependent on this class
I have a java aplication and I´m moving to dynamic web projet.
The desktop application works fine, but in the dynamic web project I´m getting this error:
java.lang.NoSuchMethodError: com.sun.jna.Native.register(Ljava/lang/String;)V
at net.sourceforge.tess4j.TessAPI1.<clinit>(TessAPI1.java:44)
The line 44 in the TessAPI1 library is
Native.register(WINDOWS ? LIB_NAME : LIB_NAME_NON_WIN);
what is the possible cause of this error?
The implementation of your interface is not present or is not at the correct version. Update the implementation version where it has that method implemented.
public class NoSuchMethodError
extends IncompatibleClassChangeError
Thrown if an application tries to call a specified method of a class (either static or instance), and that class no longer has a definition of that method.
Normally, this error is caught by the compiler; this error can only occur at run time if the definition of a class has incompatibly changed.