首页 文章

Application start方法中的JavaFx Gui异常

提问于
浏览
0

我基本上只有一个没有编码的Gui,并且仍然有一个例外,虽然之前有一些工作guis与一些小代码 . 所以最让人困惑的是..基本上只有一个gui,并且有很多代码要删除,修复..所以为什么这个gui没有出现?附: 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

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

<?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

sun.reflect.DelegatingMethodAccessorImpl.invoke(NativeMethodAccessorImpl.invoke:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl)的sun.reflect.NativeMethodAccessorImpl.invoke0(本地方法)中的应用程序启动方法java.lang.reflect.InvocationTargetException异常.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)在sun.launcher.LauncherHelper的java.lang.reflect.Method.invoke(Method.java:483)$ FXHelper.main(LauncherHelper.java:767)引起:java.lang.RuntimeException:Application start中的异常com.sun.javafx的方法.application.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)引起: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.FXMLLoa der.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) at application.Main.start(Main.java:21)at com.sun.javafx.application.LauncherImpl.lambda $ launchApplication1 $ 153(启动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 )在java.security.AccessController.doPrivileged(Native Method )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:102)at com.sun.glass.ui.win.WinApplication $$ Lambda $ 37 / 1109371569.run(Unknown Source)... 1更多引起:java.lang.IllegalAccessException:Class sun .reflect.misc.ReflectUtil无法在java.lang.Class.newInstance(Class.java:432)的sun.reflect.Reflection.ensureMemberAccess(Reflection.java:101)上访问带有修饰符“”的类application.Controller的成员 . at sun.reflect.misc.ReflectUtil.newInstance(ReflectUtil.java:51)at javafx.fxml.FXMLLoader $ ValueElement.processAttribute(FXMLLoader.java:923)... 27 more异常运行的应用程序应用程序.Main

1 回答

  • 0

    这里有两个问题:

    因此,对于2.将 changelog.setEffect(ds); 从控制器移动到 initialize 方法 .

相关问题