2017-01-19 3 views
-1

Привет, ребята, я новичок в javafx, я работал над простым приложением для сотрудников ... но имею эту болезненную ошибку, когда я нажимаю кнопку, чтобы открыть новый этап. Вот мой кодИсключение загрузки JAVAFX при открытии нового этапа

package employee; 
import javafx.application.Application; 
import javafx.fxml.FXMLLoader; 
import javafx.scene.Scene; 
import javafx.scene.layout.BorderPane; 
import javafx.stage.Modality; 
import javafx.stage.Stage; 
import java.io.IOException; 

public class Main extends Application{ 
private static Stage primaryStage; 
private static BorderPane mainLayout; 
enter code here 

public static void main(String[]args){ 
    launch(args); 
    } 

@Override 
public void start(Stage primaryStage) throws IOException { 
this.primaryStage = primaryStage; 
this.primaryStage.setTitle("Employee App"); 

    showMainView(); 
    showMainItems(); 
} 

     private void showMainView() throws IOException { 

     FXMLLoader loader = new FXMLLoader(); 
     loader.setLocation(Main.class.getResource("view/MainView.fxml")); 
     mainLayout = loader.load(); 
     Scene scene = new Scene(mainLayout); 
     primaryStage.setScene(scene); 
     primaryStage.show(); 
    } 

    public static void showMainItems() throws IOException { 



     FXMLLoader loader; 
     loader = new FXMLLoader(); 
     loader.setLocation(Main.class.getResource("view/MainItems.fxml")); 
     BorderPane mainItemsLayout; 
     mainItemsLayout = loader.load(); 
     mainLayout.setCenter(mainItemsLayout); 

    } 


    public static void showElectricalScene() throws IOException { 

     FXMLLoader loader = new FXMLLoader(); 
     loader.setLocation(Main.class.getResource("electrical/ElectricalDep.fxml")); 
     BorderPane electricalLayout = loader.load(); 
     mainLayout.setCenter(electricalLayout); 

    } 

    public static void showMechanicalScene() throws IOException { 

    FXMLLoader loader = new FXMLLoader(); 
    loader.setLocation(Main.class.getResource("mechanical/MechanicalDep.fxml")); 
    BorderPane mechanicalLayout = loader.load(); 
    mainLayout.setCenter(mechanicalLayout); 

} 


    public static void showAddButtonStage() throws IOException { 

    FXMLLoader loader = new FXMLLoader(); 
    loader.setLocation(Main.class.getResource("view/addNewEmployee.fxml")); 
    BorderPane addButton = loader.load(); 

    // BorderPane root = (BorderPane) FXMLLoader.load(Main.class.getResource("view/addNewEmployee.fxml")); 
    Stage addDialogStage= new Stage(); 
    addDialogStage.setTitle("Add New Employee"); 
    addDialogStage.initModality(Modality.WINDOW_MODAL); 
    addDialogStage.initOwner(primaryStage); 
    Scene scene= new Scene(addButton); 
    addDialogStage.setScene(scene); 
    addDialogStage.showAndWait(); 

} 

} 

здесь ошибка


Exception in thread "JavaFX Application Thread" java.lang.RuntimeException:     java.lang.reflect.InvocationTargetException 
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1768) 
at  javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1651) 
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86) 
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) 
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) 
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) 
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) 
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) 
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49) 
at javafx.event.Event.fireEvent(Event.java:204) 
at javafx.scene.Node.fireEvent(Node.java:8175) 
at javafx.scene.control.Button.fire(Button.java:185) 
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182) 
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96) 
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89) 
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218) 
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80) 
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238) 
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191) 
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59) 
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58) 
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56) 
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114) 
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74) 
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54) 
at javafx.event.Event.fireEvent(Event.java:204) 
at javafx.scene.Scene$MouseHandler.process(Scene.java:3746) 
at javafx.scene.Scene$MouseHandler.access$1800(Scene.java:3471) 
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1695) 
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2486) 
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:314) 
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:243) 
at java.security.AccessController.doPrivileged(Native Method) 
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:345) 
at com.sun.glass.ui.View.handleMouseEvent(View.java:526) 
at com.sun.glass.ui.View.notifyMouse(View.java:898) 
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39) 
at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112) 
at java.lang.Thread.run(Thread.java:745) 
Caused by: java.lang.reflect.InvocationTargetException 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at  sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:483) 
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71) 
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:483) 
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275) 
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1765) 
... 47 more 
Caused by: javafx.fxml.LoadException:/C:/Users/Dorcas%20Adegboye/IdeaProjects/EmployeeApp/out/production/EmployeeApp/employee/view/addNewEmployee.fxml 

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2617) 
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2543) 
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2441) 
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3230) 
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3191) 
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3164) 
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3140) 
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3120) 
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3113) 
at employee.Main.showAddButtonStage(Main.java:82) 
at employee.view.MainViewController.addBtn(MainViewController.java:26) 
... 57 more 
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[1,1] 
Message: Premature end of file. 
at com.sun.org.apache.xerces.internal.impl.XMLStreamReaderImpl.next(XMLStreamReaderImpl.java:601) 
at javax.xml.stream.util.StreamReaderDelegate.next(StreamReaderDelegate.java:88) 
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2513) 
... 66 more 

хорошие ответы оценили.

+2

Ошибка в вашем FXML файле ('addNewEmployee.fxml'), который, как представляется, быть пустым. –

+0

Спасибо, что именно там была ошибка. У меня был пустой (addNewEmployee.fxml) –

+0

Вы можете найти http://stackoverflow.com/q/3988788/2775450, как правило, полезно для использования трассировки стека для устранения неполадок. –

ответ

0

Попробуйте загрузить ресурс с полным пакетом, например .:

loader.setLocation(Main.class.getResource("/employee/view/MainView.fxml")); 
Смежные вопросы