首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java相关 >

JavaFX 匯进 fxml檔錯誤

2013-04-02 
JavaFX 匯入 fxml檔錯誤fxml檔中包含event事件類別 SMSevent錯誤訊息 : java.lang.IllegalAccessException

JavaFX 匯入 fxml檔錯誤
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>

[解决办法]
应该是没有参数引起的


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

看下

热点排行