我搜索了问题,但没有找到有效的解决方案。
我目前正在尝试使用JavaFx编写应用程序,并且正在尝试为FXML文件加载控制器,但是即使SceneBuilder找到了,Eclipse也没有。
这是我的FXML文件(位于main / resources /中:
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ButtonBar?>
<?import javafx.scene.control.ChoiceBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ListView?>
<?import javafx.scene.control.ScrollBar?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane fx:id="homeScreenAnchorPane" prefHeight="544.0" prefWidth="700.0" xmlns="http://javafx.com/javafx/10.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="view.GlobalVueController">
<children>
<ListView fx:id="listView" layoutY="116.0" prefHeight="431.0" prefWidth="685.0" />
<ScrollBar layoutX="686.0" layoutY="116.0" orientation="VERTICAL" prefHeight="431.0" prefWidth="14.0" />
<ButtonBar layoutX="14.0" layoutY="14.0" prefHeight="40.0" prefWidth="458.0">
<buttons>
<TextField fx:id="searchBar" prefHeight="26.0" prefWidth="491.0" />
</buttons>
</ButtonBar>
<Button fx:id="addButtonHS" layoutX="502.0" layoutY="14.0" mnemonicParsing="false" prefHeight="40.0" prefWidth="75.0" text="Add" />
<Button fx:id="supprButtonHS" layoutX="611.0" layoutY="14.0" mnemonicParsing="false" prefHeight="40.0" prefWidth="75.0" text="Suppr" />
<Label layoutX="14.0" layoutY="74.0" text="Flitrer par groupe :">
<font>
<Font size="18.0" />
</font>
</Label>
<ChoiceBox fx:id="groupFilter" layoutX="192.0" layoutY="75.0" prefWidth="150.0" />
</children>
</AnchorPane>
这是我的主要应用程序(在其中加载FXML):
public class ContactApp extends Application
{
public static void main( String[] args )
{
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
// TODO Auto-generated method stub
primaryStage.setTitle("Homescreen");
StageService.getInstance().setPrimaryStage(primaryStage);
showHomeScreen();
}
public void showHomeScreen() {
FXMLLoader loader = new FXMLLoader();
loader.setLocation(ContactApp.class.getResource("/view/GlobalVue.fxml"));
System.out.println("bla");
try {
AnchorPane rootLayout = loader.load();
Scene scene = new Scene(rootLayout);
StageService.getInstance().getPrimaryStage().setScene(scene);
StageService.getInstance().getPrimaryStage().show();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
还有我的控制器(位于应用程序的程序包视图中):
public class GlobalVueController {
@FXML
private AnchorPane homeScreenAnchorPane;
@FXML
private ListView<Contact> listView;
@FXML
private TextField searchBar;
@FXML
private Button addButtonHS;
@FXML
private Button supprButtonHS;
@FXML
private ChoiceBox<Category> groupFilter;
private ObservableList<Contact> observableContacts;
public GlobalVueController() {
observableContacts = FXCollections.observableArrayList();
ContactDao daoContact = new ContactDao();
daoContact.listAllContacts("").forEach( e-> observableContacts.add(e));
}
@FXML
public void init() {
listView.setItems(observableContacts);
listView.setCellFactory(observableContacts -> new ContactViewController());
}
}
最后我得到错误:
javafx.fxml.LoadException:
/D:/ISEN/Cours/M1/Projets/Contact_App/contact_app/target/classes/view/GlobalVue.fxml:13
at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2601)
at javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:103)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:922)
at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoader.java:971)
at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:220)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:744)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2527)
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2409)
at isen.java2.app.ContactApp.showHomeScreen(ContactApp.java:38)
at isen.java2.app.ContactApp.start(ContactApp.java:29)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$147(WinApplication.java:177)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: view.GlobalVueController
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:920)
... 18 more
感谢您的帮助!
答案 0 :(得分:0)
好吧,我只需要更新我的Maven项目!