Issue
as a Java programmer, I have recently decided to learn Kotlin and have encountered a problem with Eclipse and Kotlin. Both Eclipse and the plugins were all updated to the latest version.
Here's the situation in Eclipse.
Code that works totally fine:
fun main(args: Array<String>) {
println("Starting program...")
var a = 10
var b = 5
println("Variables \"a\" and \"b\" initialized, printing variables:")
println(a)
println(b)
println("Program ended.")
}
Output: Starting program... Variables initialized, printing variables: 10 5 Program ended.
Code that does not work at all, note that I changed the values of a and b (important):
fun main(args: Array<String>) {
println("Starting program...")
var a = 20
var b = 10
println("Variables \"a\" and \"b\" initialized, adding both together...")
//adding a and b together
var c = a+b //**Error occurs for a fraction of a second**: ERROR: Cannot access 'java.io.Serializable' which is a supertype of 'kotlin.Int'. Check your module classpath for missing or conflicting dependencies
println("Printing sum of \"a\" and \"b\": ")
println(c)
println("Program ended.")
}
Output: Same output as from the last successful run
I needed to record what Eclipse was doing, just so that I can read the error message when the footage was paused.
After that, I checked the classpath (as the error message suggested) and no dependencies were missing.
Here's one rather strange observation that I made. Restarting Eclipse and running the same "erroneous" code results in the output from the last successful run (before restarting Eclipse), in this case it was Starting program... Variables initialized, printing variables: 10 5 Program ended.
What I tried
- searched StackOverFlow for an existing/similar topic
- checked if the latest Kotlin compiler was installed (it is)
- compiled the "erroneous" .kt file manually via command prompt (it worked fine, so I guess it's a problem with Eclipse)
- configured the build path and moved the Kotlin libraries from class path to module path, which resulted in Eclipse not being able to run the program at all (ClassNotFoundException)
- deleted the Kotlin library from the build path completely, this resulted in working code, but only without basic arithmetic operations with the integer values
- restarted Eclipse again and noticed that the Kotlin libraries were back in the class path, without changing it myself
- deliberately tried to switch perspectives to Java and back to Kotlin, error persists
- tried to run the program in vs code, it worked there...
- reinstalled Eclipse and the Kotlin plugins, didn't work
What's my question(s)
Does someone know what causes this strange behaviour or has experienced something similar? And if so, is there something that I could try which worked for you, or is there something that I haved missed out on?
Thank you for reading
Thank you very much for reading!
Solution
Digging deeper into the matter here, I finally found a solution that is over 3 years old, but still works out: cannot access 'java.io.Serializable'
Answered By - Frontalschaden
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.