Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/369.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
应用程序启动方法中的JavaFXGUI异常_Java_User Interface_Javafx_Javafx 8 - Fatal编程技术网

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

应用程序启动方法中的JavaFXGUI异常,java,user-interface,javafx,javafx-8,Java,User Interface,Javafx,Javafx 8,我基本上只有一个未编码的Gui,尽管之前有一些工作Gui,但仍然有这个例外,只需要一些代码。那么最让人困惑的是。。基本上只有一个gui,没有太多的代码需要删除、修复。。那么为什么这个gui没有出现呢?p、 当然,s.fxml在正确的目录中 MAIN package application; import javafx.application.Application; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import

我基本上只有一个未编码的Gui,尽管之前有一些工作Gui,但仍然有这个例外,只需要一些代码。那么最让人困惑的是。。基本上只有一个gui,没有太多的代码需要删除、修复。。那么为什么这个gui没有出现呢?p、 当然,s.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();


}
}
控制器

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


错误

应用程序启动方法中的异常 java.lang.reflect.InvocationTargetException位于 sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)位于 invoke(NativeMethodAccessorImpl.java:62 )在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl .java:43)在java.lang.reflect.Method.invoke(Method.java:483)在 com.sun.javafx.application.LaunchImpl.launchApplicationWithArgs(LaunchIM pl.java:363)at com.sun.javafx.application.LaunchImpl.launchApplication(LaunchImpl.java: 303)在sun.reflect.NativeMethodAccessorImpl.invoke0(本机方法)处 在 invoke(NativeMethodAccessorImpl.java:62 )在 sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl .java:43)在java.lang.reflect.Method.invoke(Method.java:483)在 sun.launcher.launchelper$FXHelper.main(launchelper.java:767) 原因:java.lang.RuntimeException:应用程序启动时出现异常 方法在 com.sun.javafx.application.LaunchImpl.launchApplication1(LaunchImpl.java :875)在 com.sun.javafx.application.launchempl.lambda$launchApplication$147(launch java:157)在 com.sun.javafx.application.launchempl$$Lambda$48/128893786.run(未知 java.lang.Thread.run(Thread.java:745)上的源代码)由以下原因引起: javafx.fxml.LoadException: /E:/Programming/Java/WorkSpace/FxConverter/bin/application/Gui.fxml:11

在 fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2595) 在javafx.fxml.fxmloader.access$700(fxmloader.java:104)上 FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:930) 在 javafx.fxml.FXMLLoader$InstanceDecrationElement.processAttribute(FXMLLoade r、 java:967)at fxml.FXMLLoader$Element.processStartElement(FXMLLoader.java:216) 在 fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:740) 在javafx.fxml.fxmloader.processStartElement(fxmloader.java:2701) 在javafx.fxml.fxmloader.loadImpl(fxmloader.java:2521)中 javafx.fxml.fxmloader.loadImpl(fxmloader.java:2435)位于 javafx.fxml.fxmloader.loadImpl(fxmloader.java:3208)位于 javafx.fxml.fxmloader.loadImpl(fxmloader.java:3169)位于 javafx.fxml.fxmloader.loadImpl(fxmloader.java:3142)位于 javafx.fxml.fxmloader.loadImpl(fxmloader.java:3118)位于 javafx.fxml.fxmloader.loadImpl(fxmloader.java:3098)位于 javafx.fxml.fxmloader.load(fxmloader.java:3091)位于 application.Main.start(Main.java:21)位于 com.sun.javafx.application.launchempl.lambda$launchApplication1$153(启动 java:821)在 com.sun.javafx.application.launchempl$$Lambda$51/1596489439.run(未知 因此,在 com.sun.javafx.application.PlatformImpl.lambda$runAndWait$166(PlatformImpl.j 艾娃:323)在 com.sun.javafx.application.platformpl$$Lambda$44/1051754451.run(未知 因此,在 com.sun.javafx.application.PlatformImpl.lambda$null$164(PlatformImpl.java:29 2) 在 com.sun.javafx.application.platformpl$$Lambda$47/1001120425.run(未知 在java.security.AccessController.doPrivileged(本机 方法)在 com.sun.javafx.application.PlatformImpl.lambda$runLater$165(PlatformImpl.jav a:291)在 com.sun.javafx.application.platformpl$$Lambda$45/1775282465.run(未知 因此,在 com.sun.glass.ui.invokelateDispatcher$Future.run(invokelateDispatcher.java :95)在com.sun.glass.ui.win.WinApplication.\u runLoop(本机方法) 在 com.sun.glass.ui.win.WinApplication.lambda$null$141(WinApplication.java:102) 在 com.sun.glass.ui.win.WinApplication$$Lambda$37/1109371569.run(未知) 来源)。。。1更多原因:java.lang.IllegalAccessException: 类sun.reflect.misc.reflectil无法访问类的成员 应用程序。在处带有修饰符“”的控制器 sun.reflect.Reflection.ensureMemberAccess(Reflection.java:101)位于 java.lang.Class.newInstance(Class.java:432)位于 sun.reflect.misc.reflectil.newInstance(reflectil.java:51)位于 FXMLLoader$ValueElement.processAttribute(FXMLLoader.java:923) ... 27更多运行应用程序的异常。Main


这里有两个问题:

  • 控制器的构造函数必须是公共的。参考此线程:
  • 控制器构造函数将不起作用,因为您正试图访问一个此时不可用的字段

  • 第二次也是如此。移动
    changelog.setEffect(ds)
    从控制器到
    初始化
    方法。

    删除了关于ds效果的所有内容,这一行来自构造函数和“DropShadow ds=new DropShadow();”仍然是相同的错误,所以我认为这不是问题所在。但是谢谢你以后给我的提示。@RaXenel你有什么错误?有没有stacktrace?添加了一个错误,在gui中添加了几个组件之前工作得很好。仍然是一样的,构造函数是空的,所以我认为它对此没有任何影响。使用
    public
    构造函数会得到完全相同的错误消息?这似乎不太可能……除了@eckig的答案中显示的错误外,我还看到了另一个错误:在控制器中,您将
    组定义为
    按钮组(不确定这是什么,您没有显示导入);它应该是一个
    <?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>