2016-10-05 8 views
-2

JavaFXを学び始めました。私はログインシーンを作成したい、私の目標は在庫アプリケーションを書くことです。私はjava 8でEclipseで次のコードを実行すると、エラーが発生します。私を助けてください。 fxmlは、シーンビルダを使用して生成されます。アプリケーション開始メソッド(JavaFX)の例外

Main.java:

package application; 

import javafx.application.Application; 
import javafx.fxml.FXMLLoader; 
import javafx.stage.Stage; 
import javafx.scene.Parent; 
import javafx.scene.Scene; 
import javafx.scene.layout.BorderPane; 

public class Main extends Application { 


@Override 
     public void start(Stage stage) throws Exception { 
     Parent root = FXMLLoader.load(getClass().getResource("LoginStage.fxml")); 

     Scene scene = new Scene(root); 

     stage.setScene(scene); 
     stage.setTitle("HelloSwingNode Sample"); 
     stage.show(); 
    } 

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

LoginStage.fxml:

<?import javafx.scene.effect.*?> 
<?import javafx.scene.control.*?> 
<?import javafx.scene.text.*?> 
<?import com.jfoenix.controls.*?> 
<?import java.util.*?> 
<?import java.lang.*?> 
<?import javafx.scene.layout.*?> 
<?import javafx.scene.layout.AnchorPane?> 


<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="467.0" prefWidth="716.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="Main.Controller"> 
    <children> 
     <Pane layoutX="31.0" layoutY="22.0" prefHeight="413.0" prefWidth="644.0" style="-fx-background-color: #ffffff;"> 
     <children> 
      <JFXTextField fx:id="userName" cacheShape="false" focusColor="#8fc9f5" layoutX="123.0" layoutY="147.0" maxWidth="386.0" minWidth="210.0" prefHeight="41.0" prefWidth="386.0" promptText="Username" unFocusColor="BLACK"> 
       <font> 
        <Font size="14.0" /> 
       </font> 
      </JFXTextField> 
      <JFXPasswordField fx:id="password" focusColor="#8fc9f5" layoutX="123.0" layoutY="221.0" maxWidth="386.0" minWidth="205.0" prefHeight="41.0" prefWidth="386.0" promptText="Password"> 
      <font> 
        <Font size="14.0" /> 
       </font> 
      </JFXPasswordField> 
      <JFXButton fx:id="login" alignment="CENTER" buttonType="RAISED" layoutX="123.0" layoutY="313.0" onAction="#makeLogin" prefHeight="41.0" prefWidth="386.0" ripplerFill="WHITE" style="-fx-background-color: #9999ff;" text="Login" textAlignment="CENTER" textFill="#e5e5ff"> 
       <font> 
       <Font name="System Bold" size="20.0" /> 
       </font> 
      </JFXButton>a 
      <Label layoutX="123.0" layoutY="21.0" prefHeight="74.0" prefWidth="272.0" style="-fx-background-color: #ffffff;" text="Welcome" textFill="#8cc9ff"> 
       <font> 
        <Font size="50.0" /> 
       </font> 
      </Label> 
       <Label layoutX="123.0" layoutY="95.0" prefHeight="31.0"  prefWidth="194.0" style="-fx-background-color: #ffffff;" text="To our inventory system" textFill="#949292"> 
        <font> 
         <Font size="17.0" /> 
        </font> 
       </Label> 
      </children> 
      <effect> 
       <DropShadow /> 
      </effect> 
      </Pane> 
     </children> 
    </AnchorPane> 

私のエラー:

Exception in Application start method 
java.lang.reflect.InvocationTargetException 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source) 
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389) 
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328) 
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) 
at java.lang.reflect.Method.invoke(Unknown Source) 
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source) 
Caused by: java.lang.RuntimeException: Exception in Application start method 
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917) 
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(LauncherImpl.java:182) 
at java.lang.Thread.run(Unknown Source) 
Caused by: javafx.fxml.LoadException: 
/C:/Users/Kelvinyu/workspace/InvApp/bin/application/LoginStage.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.loadImpl(FXMLLoader.java:3214) 
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3175) 
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3148) 
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3124) 
at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3104) 
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3097) 
at application.Main.start(Main.java:16) 
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(LauncherImpl.java:863) 
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(PlatformImpl.java:326) 
at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295) 
at java.security.AccessController.doPrivileged(Native Method) 
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(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$148(WinApplication.java:191) 
... 1 more 
Caused by: java.lang.ClassNotFoundException: Main.Controller 
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) 
... 22 more 
Exception running application application.Main 
+0

"私はエラーを取得する":

現在FXMLLoaderは、あなたのプロジェクトは次のようになり前提としています。何のエラー?それは何[あなたが間違っていると伝えますか](http://stackoverflow.com/questions/3988788/what-is-a-stack-trace-and-how-can-i-use-it-to-debug-my -application-errors)?あなたの質問にスタックトレースを投稿してください。 –

+0

OK、スタックトレースを投稿しました –

+0

コントローラクラスが見つかりません。パッケージ名は正しいですか? –

答えて

0

ここで重要な行は、次のとおりです。

FXML:fx:controller="Main.Controller"
スタックトレース:Caused by: java.lang.ClassNotFoundException: Main.Controller

FXMLLoaderあなたはリフレクション経由FXMLで宣言されたあなたのコントローラクラスを見つけようとしています。私はあなたがクラスMain.Controllerを持っていないと思う。

src 
|-> Main (package) 
| |-> Controller.java (class) 
|-> Main.java (class) 
関連する問題