Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NoClassDefFoundError when using Exposed

I'm using Exposed as my database library and I'm getting these errors when I try to run my code:

Exception in thread "main" java.lang.NoClassDefFoundError: kotlin/reflect/full/KClasses
    at org.jetbrains.exposed.sql.Table.clone(Table.kt:196)
    at org.jetbrains.exposed.sql.Table.cloneWithAutoInc(Table.kt:234)
    at org.jetbrains.exposed.sql.Table.autoIncrement(Table.kt:238)
    at org.jetbrains.exposed.sql.Table.autoIncrement$default(Table.kt:238)
    at vanilla.jubeatbook.data.Songs.<init>(SQLObjects.kt:14)
    at vanilla.jubeatbook.data.Songs.<clinit>(SQLObjects.kt:13)
    at vanilla.jubeatbook.backend.MainKt$main$1.invoke(Main.kt:22)
    at vanilla.jubeatbook.backend.MainKt$main$1.invoke(Main.kt)
    at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.inTopLevelTransaction(ThreadLocalTransactionManager.kt:70)
    at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:58)
    at org.jetbrains.exposed.sql.transactions.ThreadLocalTransactionManagerKt.transaction(ThreadLocalTransactionManager.kt:49)
    at vanilla.jubeatbook.backend.MainKt.main(Main.kt:21)
    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 com.intellij.rt.execution.application.AppMain.main(AppMain.java:147)
Caused by: java.lang.ClassNotFoundException: kotlin.reflect.full.KClasses
    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)
    ... 17 more

Code snippet for SQLObjects.kt:

object Songs : Table() {
    val _id = integer("_id").autoIncrement().primaryKey() // Line 14
    val songId = integer("song_id")
    val title = text("title")
    val artist = text("artist")
    val levelBSC = integer("level_bsc")
    val levelADV = integer("level_adv")
    val levelEXT = integer("level_ext")
}

I think I followed the sample code right but I can't just figure out what throws these.

like image 503
shiftpsh Avatar asked Jun 13 '17 15:06

shiftpsh


People also ask

How do I fix NoClassDefFoundError?

You can fix NoClassDefFoundError error by checking following: Check the exception stack trace to know exactly which class throw the error and which is the class not found by java.

How do you prevent NoClassDefFoundError?

NoClassDefFoundError, which means the Class Loader file responsible for dynamically loading classes can not find the . class file. So to remove this error, you should set your classpath to the location where your Class Loader is present. Hope it helps!!

What is exposed in Kotlin?

Exposed is an open-source library (Apache license) developed by JetBrains, which provides an idiomatic Kotlin API for some relational database implementations while smoothing out the differences among database vendors.

What is Java NoClassDefFoundError?

What Is java.lang.NoClassDefFoundError? When the Java Runtime runs a Java program, it does not load all the classes and dependencies at once. Instead, it calls upon the Java Classloader to load classes in memory as-and-when-required. While loading a class, if the Classloader cannot find the class's definition, it throws the NoClassDefFoundError.

Why do I get NoClassDefFoundError when I run a script?

Any start-up script is overriding Classpath environment variable. Because NoClassDefFoundError is a subclass of java.lang.LinkageError it can also come if one of it dependency like native library may not available. Check for java.lang.ExceptionInInitializerError in your log file.

What causes NoClassDefFoundError in J2EE?

If you are working in J2EE environment than the visibility of Class among multiple Classloader can also cause java.lang.NoClassDefFoundError, see examples and scenario section for detailed discussion. Verify that all required Java classes are included in the application’s classpath.

What is class2 classnotfoundexception in Java?

2. ClassNotFoundException ClassNotFoundException is a checked exception which occurs when an application tries to load a class through its fully-qualified name and can not find its definition on the classpath. This occurs mainly when trying to load classes using Class.forName (), ClassLoader.loadClass () or ClassLoader.findSystemClass ().


1 Answers

You need to add kotlin-reflect as a dependency to your project.

like image 101
yole Avatar answered Sep 25 '22 19:09

yole