Cannot inherit from final class error - java

What does this error mean .. It runs fine in Eclipse but not in intellij idea
Exception in thread "main" java.lang.VerifyError: Cannot inherit from final class
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at com.couchbase.client.ViewConnection.createConnections(ViewConnection.java:120)
at com.couchbase.client.ViewConnection.<init>(ViewConnection.java:100)
at com.couchbase.client.CouchbaseConnectionFactory.createViewConnection(CouchbaseConnectionFactory.java:179)
at com.couchbase.client.CouchbaseClient.<init>(CouchbaseClient.java:243)
at com.couchbase.client.CouchbaseClient.<init>(CouchbaseClient.java:175)
at com.couchbase.App.putincbase(App.java:122)
at examplesCons.TestCons.run(TestCons.java:89)
at examplesCons.TestCons.main(TestCons.java:121)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:120)
I get this error when I try to run couchbase using couchbase-client-1.1.6.jar from Intellij IDea.

if you're using kotlin, add open to your class (extends RealmObject) declaration
open class Foo() {
}

The message means what it says.
Somewhere, somehow you have managed to create a class that extends a superclass, where the superclass has been declared as final.
The most likely cause is that you have a conflict between your build classpath and your launch classpath. In other words, you are compiling your subclass against a version of the superclass that is not final, and then running against a version that is final. The verifier is saying (correctly) that this is wrong.
If it is not your build / one of your classes that is causing this, then it is some internal conflict within the CouchDB client classes that you are using. Indeed the fact that this is a VerifyError rather than an IncompatibleClassChangeError suggests that this maybe a problem with some dynamically generated bytecodes.

I also faced this with IntelliJ Idea: 2018.3 Community Edition, However running following fixed it for me:
mvn -U idea:idea clean compile install -DskipTests

maybe you would be extend a java class which is marked as final keyword but as you know, inheritance is not possible with final class.

Related

Getting UnsupportedClassVersionError in Eclipse JPA project which does not make sense

I have a weird situation here. I am getting an error about Java 1.7 when I am using Java 1.6 everywhere.
I am using Eclipse Kepler 32-bit.
The JPA implementation I am using is EclipseLink 2.6.0.
In Window --> Preferences --> Java --> Installed JREs, I have jdk1.6.0_34 (default) checked and its location is C:\Program Files (x86)\Java\jdk1.6.0_34. This is the print screen:
I create a new JPA Project. In Target runtime I selected jdk1.6.0_34. This is the print screen:
I click on Modify... button in Configuration section to confirm I am working on Java 1.6. This is the print screen:
I then created a simple class to test JPA:
package com.test;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
public class TestJPA {
public static void main(String[] args) {
EntityManagerFactory emf = Persistence.createEntityManagerFactory("MyTestJpaProject");
emf.close();
}
}
When I run it I got an error message:
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/eclipse/persistence/jpa/PersistenceProvider : Unsupported major.minor version 51.0
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at javax.persistence.spi.PersistenceProviderResolverHolder$DefaultPersistenceProviderResolver.getPersistenceProviders(PersistenceProviderResolverHolder.java:117)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:76)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
at com.test.TestJPA.main(TestJPA.java:16)
This is strange. I am using Java 1.6 everywhere yet Eclipse is giving me this error message about Java 1.7. What could be the reason?
This means that some plugin you are using was built using java 1.7 and it would require 1.7 or greater jre. Check the plugin which contains the class mentioned in the stack trace.

Java NoClassDefFoundError in Command Line

I'm getting the NoClassDefError when I try to run my program from the command line. It works fine in Netbeans, and javac compiles correctly.
I have a class called DistributedSystem which so far is only supposed to print "hello.".
The directory is src/distributedsystem/ which contains DistributedSystem.java, and DistributedSystem.class after the compile.
If I'm inside src/distributedsystem/ and run
java DistributedSystem
then I get
Exception in thread "main" java.lang.NoClassDefFoundError: DistributedSystem (wrong name: distributedsystem/DistributedSystem)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
I also get the exact same error if I'm inside src/distributedsystem/ and run
java -cp . DistributedSystem
which is what I thought would fix the problem. I have also tried making sure classpath isn't set somewhere else, even though -cp should overwrite it. Anyone have any ideas what could be wrong?
Go to folder src then compile from there and then run
The classpath should point to the base directory. It looks as if you are attempting to run class DistributedSystem in package distributedsystem, but your classpath is set to project/bin/distributedsystem instead of project/bin.

Errors with Java Applet on web

A java applet that I wrote works exactly as intended when I run it from the code in the applet viewer on my computer. However, when I uploaded it to my website, I get a series of errors. I looked up the errors but can't find any useful information to help figure out the problem. Here are the errors.
java.lang.NoClassDefFoundError: Main
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:247)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:249)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:179)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at sun.plugin2.applet.Plugin2ClassLoader.loadCode(Plugin2ClassLoader.java:678)
at sun.plugin2.applet.Plugin2Manager.createApplet(Plugin2Manager.java:3045)
at sun.plugin2.applet.Plugin2Manager$AppletExecutionRunnable.run(Plugin2Manager.java:1497)
at java.lang.Thread.run(Thread.java:680)
Caused by: java.lang.ClassNotFoundException: Main
at sun.plugin2.applet.Applet2ClassLoader.findClass(Applet2ClassLoader.java:252)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass0(Plugin2ClassLoader.java:249)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:179)
at sun.plugin2.applet.Plugin2ClassLoader.loadClass(Plugin2ClassLoader.java:160)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 13 more
Exception: java.lang.NoClassDefFoundError: Main
I understand that this might not be descriptive enough without a sample of my code but can anyone discern anything from these errors? Thanks
It simply means the class Main referenced in your code is not included in the applet.
Most likely you did not included the class when exporting to jar.
It'd be great if you included your code, but the problem is likely that you're referencing a class called Main, yet none exists in the CLASSPATH of the service dumping this exception.
You likely need to either create (or rename!) the source to "Main.java" and build a Main.class and put it in the correct path or alter the path to reference where Main.class (or the archive containing Main.class) is stored.

NoClassDefFoundError while running on 64bit machine

I am getting the following exception while service startup on a 64bit Machine.
But the code runs fine on a 32bit machine.
java.lang.NoClassDefFoundError: org/objectweb/asm/commons/EmptyVisitor
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at org.springframework.context.support.GenericApplicationContext.<init (GenericApplicationContext.java:103)
at org.springframework.context.support.GenericApplicationContext.<init>(GenericApplicationContext.java:125)
at org.springframework.coral.CoralApplicationContext.<init>(CoralApplicationContext.java:41)
at org.springframework.coral.CoralApplicationContext.<init>(CoralApplicationContext.java:35)
at org.springframework.coral.DisposableApplicationContext.<init>(DisposableApplicationContext.java:16)
at com.amazon.coral.spring.Launcher.<init>(Launcher.java:85)
at com.amazon.coral.spring.Launcher.main(Launcher.java:56)
Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.commons.EmptyVisitor
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 19 more
Unless you (or the libraries you use) are using native code, the underlying platform is very seldom the problem in Java programs.
From the Javadoc of NoClassDefFoundError (http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/NoClassDefFoundError.html):
Thrown if the Java Virtual Machine or a ClassLoader instance tries to
load in the definition of a class (as part of a normal method call or
as part of creating a new instance using the new expression) and no
definition of the class could be found.
The searched-for class definition existed when the currently executing
class was compiled, but the definition can no longer be found.
So it was present when the code was compiled, but not anymore when you try to run it elsewhere. The single-most typical reason for this is that the classpath is incorrectly set up, usually by not having the jar-file containing the class in question is not in the classpath. Revise your classpath definition and rerun.
If you are unfamiliar with how the classpath works I can strongly recommend reading up on the Oracle Java Tutorial.
99% likelihood is that you have a CLASSPATH environment variable on the machine where it runs, and not on the machine where it doesn't. If you're starting from a service on the latter and the command-line on the former, make that 99.9%.
Check your JAVA_HOME environment variable. If your are using eclipse IDE, check your IDE's Java Build Path.
Same problem I'm facing. I resolved the problem by adding the following 2 jar files:
asm-all 2.2.3.jar
cglib-nodep 2.1_3.jar
and remove the asm.jar and cglib.jar from the machine (64bit) where I got error.
But my question is why this problem exits in that machine. I checked CLASSPATH, PATH and JAVA_HOME environment varibles. But all are same in the two machine.
Same problem I'm facing. I resolved the problem by adding the following 2 jar files:
asm-all 3.3.1.jar
cglib-nodep 2.1.3.jar
and remove the asm.jar and cglib.jar in lib

Java ClassNotFound Exception

My application tries to execute the following line of code
JMFSecurity jmfSecurity = JMFSecurityManager.getJMFSecurity();
That line throws the following exception. Here is a stack trace:
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/media/JMFSecurityManager
at com.compunetix.vsd.stix.main.JMFUtilities.Registry.(Registry.java:71)
at com.compunetix.vsd.stix.main.JMFUtilities.JMFRunner.getJMFPropertiesFileLocation(JMFRunner.java:129)
at com.compunetix.vsd.stix.main.Main.setUpJMF(Main.java:274)
at com.compunetix.vsd.stix.main.Main.main(Main.java:166)
Caused by: java.lang.ClassNotFoundException: com.sun.media.JMFSecurityManager
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 4 more
Any ideas why this might be throwing an exception. This used to work fine. I didn't make any changes to this file. Any ideas?
ClassNotFoundException means the class isn't on your classpath.
You're using a class from the com.sun package. Those classes are implementation details, not public APIs. You might have switched to a version of the JVM that implements things differently. Generally, depending on com.sun classes is a bad idea.
As the stack trace states, the class com.sun.media.JMFSecurityManager is not found. It's presumably missing from your classpath, so check this.

Categories