0

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

  1. searched StackOverFlow for an existing/similar topic
  2. checked if the latest Kotlin compiler was installed (it is)
  3. compiled the "erroneous" .kt file manually via command prompt (it worked fine, so I guess it's a problem with Eclipse)
  4. 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)
  5. deleted the Kotlin library from the build path completely, this resulted in working code, but only without basic arithmetic operations with the integer values
  6. restarted Eclipse again and noticed that the Kotlin libraries were back in the class path, without changing it myself
  7. deliberately tried to switch perspectives to Java and back to Kotlin, error persists
  8. tried to run the program in vs code, it worked there...
  9. 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!

2
  • Make sure to use the Enhanced Kotlin for Eclipse plugin, not the Kotlin plugin from JetBrains which is badly maintained. Please tell the exact versions of Eclipse, the Enhanced Kotlin plugin and the Kotlin and Java version used in your project. Be aware that Kotlin is not vendor-neutral. Commented Jan 20, 2024 at 14:56
  • Current Eclipse version is Version: 2023-12 (4.30.0) and my project is using Kotlin version 1.7.10-release-333 (JRE 21.0.1+12-LTS-29). And yes, I am using the enhanced Kotlin plugin. Commented Jan 20, 2024 at 16:01

1 Answer 1

0

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'

Sign up to request clarification or add additional context in comments.

1 Comment

Please also include the solution that worked for you along with the link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.