![](/img/trans.png)
[英]ProGuard can't find the main method in my JavaFX application
[英]JavaFX in Scala can't find launch method
試圖查看是否可以在Scala中制作並運行JavaFX程序我遇到了一個奇怪的問題,找不到啟動方法...
這是Java代碼:
package example;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.*;
import javafx.stage.*;
public class Program extends Application {
@Override
public void start(Stage stage) throws Exception {
Parent root = FXMLLoader.load(getClass().getResource("Test.fxml"));
Scene scene = new Scene(root, 300, 275);
stage.setTitle("FXML Test");
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
以及直接標量轉換:
package example
import javafx.application.Application
import javafx.fxml.FXMLLoader
import javafx.scene._
import javafx.stage._
object Program extends Application {
override def start(stage: Stage): Unit = {
val root = FXMLLoader.load(getClass getResource "Test.fxml")
val scene = new Scene(root, 300, 275)
stage setTitle "FXML Test Scala"
stage setScene scene
stage.show
}
def main(args: Array[String]): Unit = launch(args) // this bit fails
}
我選擇進行1:1轉換,看看它是否甚至可以開始工作,但是就像我之前說過的那樣,編譯器不知道Scala版本中的launch
是什么...
那我在做什么錯呢? 更重要的是,我該如何解決?
感謝Witold Czaplewski ,在Google+ Scala小組中被問到並獲得以下工作解決方案:
package example
import javafx.application.Application
import javafx.fxml.FXMLLoader
import javafx.scene._
import javafx.stage._
object Program {
def main(args: Array[String]): Unit =
Application.launch(classOf[Program], args: _*)
}
class Program extends Application {
override def start(stage: Stage): Unit = {
val root = FXMLLoader.load(getClass() getResource "Test.fxml")
val scene = new Scene(root, 300, 275)
stage setTitle "FXML Test Scala"
stage setScene scene
stage.show
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.