简体   繁体   English

应用程序启动方法中的JavaFx Gui异常

[英]JavaFx Gui Exception in Application start method

I have basically only a not coded Gui, and still got that exception although had some working guis before with a little code. 我基本上只有一个未编码的Gui,尽管之前有一些可以正常工作的gui,但仍然有一个例外,但有一点代码。 so what confuses most.. There's basically only a gui and there isnt much code to delete, fix.. so why this gui isn't showing up? 所以最让您感到困惑的是..基本上只有一个GUI,并且没有太多要删除,修复的代码..为什么不显示该GUI? ps fxml is in the right directory, for sure ps fxml在正确的目录中

MAIN 主要

package application;

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



public class Main extends Application {

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

}

@Override
public void start(Stage stage) throws Exception {

        AnchorPane pane =  FXMLLoader.load(getClass().getResource("Gui.fxml"));
    Scene scene = new Scene(pane);
    stage.setScene(scene);
    stage.show();


}
}

CONTROLLER CONTROLLER

public class Controller implements Initializable {
DropShadow ds = new DropShadow();
@FXML
ButtonGroup group;
@FXML
RadioButton radio1;
@FXML
RadioButton radio2;
@FXML
RadioButton radio3;
@FXML
Label changelog;
@FXML
TextArea changelogarea;
@FXML
Pane panechange;
@FXML
AnchorPane mainanchor;

Controller(){
changelog.setEffect(ds);    
}







@Override
public void initialize(URL location, ResourceBundle resources) {
    // TODO Auto-generated method stub

}

}

FXML FXML

<?import javafx.scene.text.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>


<AnchorPane fx:id="mainanchor" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Controller">
   <children>
      <Pane fx:id="panechange" layoutX="106.0" layoutY="-3.0" prefHeight="406.0" prefWidth="493.0">
     <children>
        <Label fx:id="changelog" layoutX="20.0" layoutY="21.0" prefHeight="49.0" prefWidth="463.0" text="                     Change log" textAlignment="CENTER">
           <font>
              <Font size="27.0" />
           </font>
        </Label>
        <TextArea fx:id="changelogarea" layoutX="1.0" layoutY="70.0" prefHeight="329.0" prefWidth="487.0" />
     </children>
  </Pane>
  <RadioButton fx:id="radio2" layoutX="14.0" layoutY="62.0" mnemonicParsing="false" text="Valiuta">
     <toggleGroup>
        <ToggleGroup fx:id="group" />
     </toggleGroup>
  </RadioButton>
  <RadioButton fx:id="radio3" layoutX="14.0" layoutY="94.0" mnemonicParsing="false" text="Atstumai" toggleGroup="$group" />
  <RadioButton fx:id="radio1" layoutX="14.0" layoutY="32.0" mnemonicParsing="false" selected="true" text="Naujienos" toggleGroup="$group" />
   </children>
</AnchorPane>

error 错误

Exception in Application start method 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 com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherIm pl.java:363) at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java: 303) 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.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767) Caused by: java.lang.RuntimeException: Exception in Application start method at com.sun.javafx.a 应用程序启动方法java.lang.reflect.InvocationTargetException处sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处的异常sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)处sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.in com.sun.javafx.application上java.lang.reflect.Method.invoke(Method.java:483)处com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherIm pl.java:363)处的java:43)。 LauncherImpl.launchApplication(LauncherImpl.java:303)位于sun.reflect.NativeMethodAccessorImpl.invoke0(原生方法)位于sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)位于sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethod) 43)在java.lang.reflect.Method.invoke(Method.java:483)在sun.launcher.LauncherHelper $ FXHelper.main(LauncherHelper.java:767)造成原因:java.lang.RuntimeException:应用程序启动方法中的异常在com.sun.javafx.a pplication.LauncherImpl.launchApplication1(LauncherImpl.java :875) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$147(Launche rImpl.java:157) at com.sun.javafx.application.LauncherImpl$$Lambda$48/128893786.run(Unknown Sou rce) at java.lang.Thread.run(Thread.java:745) Caused by: javafx.fxml.LoadException: /E:/Programming/Java/WorkSpace/FxConverter/bin/application/Gui.fxml:11 在com.sun.javafx.application.LauncherImpl.lambda $ launchApplication $ 147(Launche rImpl.java:157)处的pplication.LauncherImpl.launchApplication1(LauncherImpl.java:875)在com.sun.javafx.application.LauncherImpl $$ Lambda $ 48 / 128893786.run(java.lang.Thread.run(Thread.java:745)处的未知)原因:javafx.fxml.LoadException:/ E:/ Programming / Java / WorkSpace / FxConverter / bin / application / Gui。 FXML:11

at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2595) at javafx.fxml.FXMLLoader.access$700(FXMLLoader.java:104) at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:930) at javafx.fxml.FXMLLoader$InstanceDeclarationElement.processAttribute(FXMLLoade r.java:967) at javafx.fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:216) at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740) at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2701) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2521) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2435) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3208) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3169) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3142) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3118) at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3098) at javafx.fxml.FXMLLoader.load(FXMLLoader.java:3091) at application.Main.start(M 在javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2595)在javafx.fxml.FXMLLoader.access $ 700(FXMLLoader.java:104)在javafx.fxml.FXMLLoader $ ValueElement.processAttribute(FXMLLoader.java:930)在javafx .fxml.FXMLLoader $ InstanceDeclarationElement.processAttribute(FXMLLoade r.java:967)在javafx.fxml.FXMLLoader $ Element.processStartElement(FXMLLoader.java:216)在javafx.fxml.FXMLLoader $ ValueElement.processStartElement(FXMLLoader.java:740)在javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2701)在javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2521)在javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2435)在javafx.fxml。 FXMLLoader.loadImpl(FXMLLoader.java:3208)位于javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3169)位于javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3142)在javafx.fxml.FXMLLoader.loadImpl(FXMLLoader .java:3118),位于javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:3098),位于javafx.fxml.FXMLLoader.load(FXMLLoader.java:3091),位于application.Main.start(M ain.java:21) at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$153(Launch erImpl.java:821) at com.sun.javafx.application.LauncherImpl$$Lambda$51/1596489439.run(Unknown So urce) at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(PlatformImpl.j ava:323) at com.sun.javafx.application.PlatformImpl$$Lambda$44/1051754451.run(Unknown So urce) at com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:29 2) at com.sun.javafx.application.PlatformImpl$$Lambda$47/1001120425.run(Unknown So urce) at java.security.AccessController.doPrivileged(Native Method) at com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.jav a:291) at com.sun.javafx.application.PlatformImpl$$Lambda$45/1775282465.run(Unknown So urce) 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$141(WinApplication.java:10 ain.java:21)at com.sun.javafx.application.LauncherImpl.lambda $ launchApplication1 $ 153(Launch erImpl.java:821)at com.sun.javafx.application.LauncherImpl $$ Lambda $ 51 / 1596489439.run(未知urce)com.sun.javafx.application.PlatformImpl.lambda $ runAndWait $ 166(PlatformImpl.j ava:323)at com.sun.javafx.application.PlatformImpl $$ Lambda $ 44 / 1051754451.run(com未知) .sun.javafx.application.PlatformImpl.lambda $ null $ 164(PlatformImpl.java:29 2)at com.sun.javafx.application.PlatformImpl $$ Lambda $ 47 / 1001120425.run(Unknown So urce)at java.security.AccessController com.sun.javafx.application.PlatformImpl.lambda $ runLater $ 165(PlatformImpl.jav a:291)处的.doPrivileged(本机方法)com.sun.javafx.application.PlatformImpl $$ Lambda $ 45 / 1775282465.run(未知) urce),位于com.sun.glass.ui的com.sun.glass.ui.win.WinApplication._runLoop(本机方法)处的com.sun.glass.ui.InvokeLaterDispatcher $ Future.run(InvokeLaterDispatcher.java:95)处。 win.WinApplication.lambda为$ null $ 141(WinApplication.java:10 2) at com.sun.glass.ui.win.WinApplication$$Lambda$37/1109371569.run(Unknown Source ) ... 1 more Caused by: java.lang.IllegalAccessException: Class sun.reflect.misc.ReflectUtil can not access a member of class application.Controller with modifiers "" at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:101) at java.lang.Class.newInstance(Class.java:432) at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51) at javafx.fxml.FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:923) ... 27 more Exception running application application.Main 2)at com.sun.glass.ui.win.WinApplication $$ Lambda $ 37 / 1109371569.run(Unknown Source)... 1更多原因:java.lang.IllegalAccessException:类sun.reflect.misc.ReflectUtil不能在sun.reflect.Reflection.ensureMemberAccess(Reflection.java:101)在java.lang.Class.newInstance(Class.java:432)处在sun.reflect.misc.ReflectUtil处使用修饰符“”访问类application.Controller的成员.newInstance(ReflectUtil.java:51)at javafx.fxml.FXMLLoader $ ValueElement.processAttribute(FXMLLoader.java:923)... 27更多正在运行应用程序application.Main的异常

There are two issues here: 这里有两个问题:

  1. The constructor of your controller has to be public. 控制器的构造函数必须是公共的。 See this thread for reference: JavaFX IllegalAccessException during FXML load() 请参阅此线程以供参考: FXML load()期间的JavaFX IllegalAccessException
  2. The controller constructor will not work, since you are trying to access a field which is not available at that point. 控制器构造函数将无法工作,因为您正在尝试访问当时不可用的字段。

So for 2. move changelog.setEffect(ds); 所以对于2.移动changelog.setEffect(ds); from the controller to the initialize method. 从控制器到initialize方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM