JavaFX 匯入 fxml檔錯誤

max81819 2013-02-28 03:17:20
fxml檔中包含event事件類別 SMSevent

錯誤訊息 : java.lang.IllegalAccessException: Class javafx.fxml.FXMLLoader$ValueElement can not access a member of class JavaFXAppTest.SMSevent with modifiers ""
file:/C:/Users/DogKing/Documents/NetBeansProjects/JavaFXAppTest/dist/JavaFXAppTest.jar!/JavaFXAppTest/sms.fxml:13
at javafx.fxml.FXMLLoader$ValueElement.processValue(FXMLLoader.java:661)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:572)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2314)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2131)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2028)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2742)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2721)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2694)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2683)
at JavaFXAppTest.MyFXML.start(MyFXML.java:23)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:206)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:173)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
at java.lang.Thread.run(Thread.java:722)

Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:403)
at com.sun.javafx.application.LauncherImpl.access$000(LauncherImpl.java:47)
at com.sun.javafx.application.LauncherImpl$1.run(LauncherImpl.java:115)
at java.lang.Thread.run(Thread.java:722)
Caused by: java.lang.RuntimeException: java.lang.IllegalAccessException: Class javafx.fxml.FXMLLoader$ValueElement can not access a member of class JavaFXAppTest.SMSevent with modifiers ""
at javafx.fxml.FXMLLoader$ValueElement.processValue(FXMLLoader.java:661)
at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:572)
at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2314)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2131)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2028)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2742)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2721)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2707)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2694)
at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2683)
at JavaFXAppTest.MyFXML.start(MyFXML.java:23)
at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319)
at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:206)
at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:173)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:29)
at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:73)
... 1 more
Caused by: java.lang.IllegalAccessException: Class javafx.fxml.FXMLLoader$ValueElement can not access a member of class JavaFXAppTest.SMSevent with modifiers ""
at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:95)
at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:261)
at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:253)
at java.lang.reflect.Field.doSecurityCheck(Field.java:983)
at java.lang.reflect.Field.getFieldAccessor(Field.java:927)
at java.lang.reflect.Field.set(Field.java:680)
at javafx.fxml.FXMLLoader$ValueElement.processValue(FXMLLoader.java:659)
... 17 more
Java Result: 1
jfxsa-run:
BUILD SUCCESSFUL (total time: 6 seconds)

我覺得主要是紅色部分那裏需要解決

-------------------------------------------------------------------
以下為主程式:
package JavaFXAppTest;
import javafx.fxml.FXML;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class MyFXML extends Application {
@Override

public void start(Stage stage) throws Exception {

Parent root = FXMLLoader.load(getClass().getResource("sms.fxml")); //載入fxml檔,所有UI介面設定都在 //fxml檔裡
Scene scene = new Scene(root);

stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
------------------------------------------------------------
SMSevent class :
package JavaFXAppTest;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.layout.*;
public class SMSevent extends AnchorPane{
@FXML
TextField user,pass,phone;
TextArea content;
Button send,clear;
Label result;
public void sendMessage(ActionEvent event) {
SMS SMStest = new SMS();
SMStest.setmessage(user.getText(),pass.getText(),phone.getText(),content.getText());
System.out.println(SMStest.go());
}


public void clearAll(ActionEvent event) {
user.setText(null);
pass.setText(null);
phone.setText(null);
content.setText(null);
}
}
------------------------------------------------------
sms.fxml:
<?xml version="1.0" encoding="UTF-8"?>

<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>

<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns:fx="http://javafx.com/fxml" fx:controller="JavaFXAppTest.SMSevent">
<children>
<AnchorPane prefHeight="400.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<children>
<Button id="enter" fx:id="send" layoutX="264.0" layoutY="309.0" mnemonicParsing="false" onAction="#sendMessage" text="送出" />
<Button fx:id="clear" layoutX="318.0" layoutY="309.0" mnemonicParsing="false" onAction="#clearAll" text="清除" />
</children>
</AnchorPane>
<Pane layoutX="10.0" layoutY="10.0" prefHeight="288.0" prefWidth="576.0">
<children>
<Label layoutX="106.0" layoutY="47.0" text="帳號:" />
<Label layoutX="106.0" layoutY="77.0" text="密碼:" />
<Label layoutX="46.0" layoutY="107.0" text="接收者手機號碼:" />
<Label layoutX="82.0" layoutY="134.0" text="訊息內容:" />
<TextField fx:id="user" layoutX="152.0" layoutY="44.0" prefWidth="200.0" />
<TextField fx:id="pass" layoutX="152.0" layoutY="74.0" prefWidth="200.0" />
<TextField fx:id="phone" layoutX="152.0" layoutY="102.0" prefWidth="200.0" />
<TextArea id="context" fx:id="content" layoutX="152.0" layoutY="134.0" prefWidth="200.0" wrapText="true" />
<Label fx:id="result" layoutX="411.0" layoutY="94.0" prefHeight="73.962890625" prefWidth="77.0" text="Label" />
</children>
</Pane>
</children>
</AnchorPane>
...全文
73 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Emilio66 2014-04-10
  • 打赏
  • 举报
回复
楼主找到问题的根源了吗??我也碰到这个问题啊
max81819 2013-02-28
  • 打赏
  • 举报
回复
謝謝fangmingshijie剛剛嘗試了 但是結果還是一樣 我原本有另一個.FXML也是同樣的問題,我讓event類別extends AnchorPane類別後就可以正常執行了,但這個用這招好像也沒辦法,還是不知道哪裡出問題。
  • 打赏
  • 举报
回复
应该是没有参数引起的

改为
public static void main(String[] args) {  
        launch(new String[]{"a","b"});  
    }  

看下

50,523

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧