Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to fix java.lang.ClassNotFoundException: kotlin.String

Tags:

java

kotlin

I'm trying to load kotlin.String using SystemClassLoader

        inputClassName = String::class.qualifiedName.toString()
        val input = ClassLoader.getSystemClassLoader()
            .loadClass(inputClassName) // here I get error

and I'm getting error. Stack trace:

Exception in thread "main" java.lang.ClassNotFoundException: kotlin.String
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
    at block.execution.Executor.init(Executor.kt:40)
    at block.AppKt.main(App.kt:50)

What am I doing wrong? How can I fix it?

like image 577
Alex Avatar asked May 08 '26 11:05

Alex


1 Answers

kotlin.String doesn't exist as a class which can be loaded, it is mapped to java.lang.String by the compiler. String::class.java.name will give you the actual name of the class.

Of course, as Mikhail Kopylov points out, there is little point loading a class by name of an already loaded class. Maybe to load it in a specific ClassLoader, but String will definitely be loaded by the system class loader anyway.

like image 151
Alexey Romanov Avatar answered May 11 '26 00:05

Alexey Romanov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!