我需要在Clojure中加载基于fxml的JavaFX场景, 但是当我尝试加载资源“view.fxml”时,它返回nil。
这是我现在的代码:
(ns ui.ui_controller
(:import (javafx.application Application)
(javafx.fxml FXMLLoader)
(javafx.scene Scene)
(javafx.stage Stage)))
(gen-class
:name ui.ui_controller
:extends javafx.application.Application)
(defn -main [& args]
(Application/launch ui.ui_controller args))
(defn -start [this stage]
(let [loc (clojure.java.io/resource "view.fxml")
root (FXMLLoader/load loc)]
(.setScene stage (Scene. root))
(.setTitle stage "JavaFXML with Clojure Example")
(.show stage)))
在resources文件夹中是view.fxml文件,应加载该文件。
在通话中(println(clojure.java.io/resource“view.fxml”))它会返回nil ...
知道这里出了什么问题吗?
谢谢!
答案 0 :(得分:1)
这是一个例子
(ns tst.clj.core
(:use clj.core
clojure.test )
(:require
[clojure.java.io :as io]
))
(def words (slurp (io/file (io/resource "count.txt"))))
(println words)
> ls -ldF resources/count.txt
-rw-rw-r-- 1 alan alan 14 Jan 3 09:01 resources/count.txt
> cat resources/count.txt
one
two
three
> lein test
one
two
three