javascalaintellij-ideajava-9scala-2.12

Intelij scala project does not support swing


I am unable to use swing library with my scala-sdk-2.12.4. I am using Java 9 version. When I try to run the program:

package rs.ac.bg.etf.zd173013m.gui

import swing._

object HelloWorld extends SimpleSwingApplication {
def top = new MainFrame {
   title = "First Swing App"
    contents = new Button {
     text = "Click me"
   }
 }
}

I get the following error:

Exception in thread "main" java.lang.IncompatibleClassChangeError: Method scala.swing.Reactor.$init$()V must be InterfaceMethodref constant
    at scala.swing.SwingApplication.<init>(SwingApplication.scala:4)
    at scala.swing.SimpleSwingApplication.<init>(SimpleSwingApplication.scala:13)
    at rs.ac.bg.etf.zd173013m.gui.HelloWorld$.<init>(Application.scala:5)
    at rs.ac.bg.etf.zd173013m.gui.HelloWorld$.<clinit>(Application.scala)
    at rs.ac.bg.etf.zd173013m.gui.HelloWorld.main(Application.scala)

Solution

  • You have incompatible JAR versions on your classpath. The code in the JAR containing "SwingApplication" was compiled against a different version of "Reactor" than the one on your classpath.

    What are you using to manage your dependencies? I guess that you are downloading them manually.

    Switch to a dependency management system like Gradle and this problem should go away, as it will ensure that all your dependencies are consistent.