ScalaFX can't find a css resource file

33 views Asked by At

I am creating a GUI for my app, and I want to style it. To add css to a scene, I use the following code:

val scene = new Scene(parent = root) {     
    stylesheets.add(getClass.getResource("a.css").toExternalForm)
}

The directory structure is as follows: structure, with the source code file in the /scala folder and a.css file in the /resources folder.

However, when I try to load the file, I get an error: java.lang.NullPointerException: Cannot invoke "java.net.URL.toExternalForm()" because the return value of "java.lang.Class.getResource(String)" is null.

My sbt file contains the following text:

ThisBuild / version := "0.1.0-SNAPSHOT"

ThisBuild / scalaVersion := "3.3.1"

lazy val root = (project in file("."))
  .settings(
    name := "My project"
  )

libraryDependencies += "org.scalafx" % "scalafx_3" % "20.0.0-R31"
libraryDependencies += "org.scala-lang" %% "toolkit" % "0.1.7"

I have also tried providing absolute path, absolute path prepended with a '/' or a '\' (I am using Windows), and relative paths starting from /src, /main, and /resources folders; nothing worked.

Any help is greatly appreciated.

0

There are 0 answers