Does anything else from the Kotlin runtime work? Can you check if a simple hello world program would compile and run?
Please try to invalidate caches and restart (File -> Invalidate Caches / Restart…).
Also BTW “Any::class.javaClass” is probably not what you meant since this expression returns the runtime Java class of the expression “Any::class”, which happens to be KClass. More likely you meant “Any::class.java”, which will give you the Java class that is the runtime representation of Any (java.lang.Object).
I'm glad it worked out. The NPE is strange though, could you please paste the stack trace for that? The simple "println(Any::class.java)" works for me.
Output:
class java.lang.Object
class java.lang.Class
null
null
class kotlin.jvm.internal.ClassReference
sun.misc.Launcher$AppClassLoader@12a3a380
Exception in thread “main” java.lang.IllegalStateException: Any::class.java.javaClas…eAsStream(“$prefix$name”) must not be null at com.iamshb.hexinterpret.MainKt.getResource(Main.kt:37) at com.iamshb.hexinterpret.MainKt.parse(Main.kt:23) at com.iamshb.hexinterpret.MainKt.main(Main.kt:17) 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:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
i tried every combination of the prints to get the resource as a stream and only the last one work.ed the stack trace were all pretty much the same
I see. This happens because java.lang.Object (which represents Any at runtime) is a core JRE class and is loaded by the bootstrap class loader. Class#getClassLoader returns null in that case, as specified in the javadoc. I recommend you to take the class loader which loaded any of the classes in your application instead of the construct that you're using because it's rather confusing and may change unexpectedly when the app is run in another environment (where the Kotlin runtime would be loaded with a different class loader). So I would just use "SomeClass::class.java.classLoader.getResourceAsStream(...)" where SomeClass is any class in your code.
*nod* easy enought.
Originally when i started this project there were no classes.
I wanted to use the MainKt class (that java sees) to load it however in the context of kotlin it didn't seem to be avaialbe (in m14 at least)
Normally in java I would use what ever class contaned the main(String…) method but this was not present in kotlin.
that said perhaps to support purely functional programming kotlin could provide a substiute in some way.