2015-01-26 132 views
0

我遇到了一個大問題,那就是確保所有文件中都沒有錯誤,並且當我運行JavaFX Application時,我得到一個包含「運行應用程序時異常」的小窗口。輸出突出的問題是在Main Class所以這是我在Main類:在JavaFX中運行應用程序時出現異常

 package amnet23; 

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

    public class AmNet23 extends Application { 

    @Override 
    public void start(Stage stage) throws Exception { 
     Parent root = FXMLLoader.load(getClass().getResource("WorkSpace.fxml")); 

     Scene scene = new Scene(root); 

     stage.setScene(scene); 
     stage.show(); 
    } 

    /** 
    * @param args the command line arguments 
    */ 
    public static void main(String[] args) { 
     launch(args); 
    } 

} 
here's the Controller class: 

    package amnet23; 


import java.io.IOException; 
import java.net.InetSocketAddress; 
import java.net.Socket; 
import java.net.URL; 
import java.util.ResourceBundle; 
import javafx.event.ActionEvent; 
import javafx.event.EventHandler; 
import javafx.fxml.FXML; 
import javafx.fxml.FXMLLoader; 
import javafx.fxml.Initializable; 
import javafx.scene.Cursor; 
import javafx.scene.Parent; 
import javafx.scene.Scene; 
import javafx.scene.control.Button; 
import javafx.scene.control.Hyperlink; 
import javafx.scene.control.Label; 
import javafx.scene.control.Tab; 
import javafx.scene.control.TabPane; 
import javafx.scene.control.TextField; 
import javafx.scene.input.KeyCode; 
import javafx.scene.input.KeyEvent; 
import javafx.scene.layout.AnchorPane; 
import javafx.scene.web.WebEngine; 
import javafx.scene.web.WebView; 
import javafx.stage.Modality; 
import javafx.stage.Stage; 
import javafx.stage.WindowEvent; 
import javax.swing.text.html.HTMLEditorKit; 

/** 
* 
* @author Ahmed 
*/ 
public class FXMLDocumentController implements Initializable { 
    Stage tt; 
    //anchor 
    AnchorPane ancpa; 
    //labels fxid 
    Label labeln1; 
    Label labeln2; 
    Label labelslo; // text field 
    Button labelsear; // help 
    Button labelpop; // about 
    Label labeloren; // nejma 
    Label labelpros; // search 
    Label labelno; 
    // text field 
    TextField text11; 
    //buttons fxid 
    //button links 
    Button but1; 
    Button but2; 
    Button but3; 
    Button but4; 
    Button but5; 
    Button but6; 
    Button but7; 
    Button but8; 
    Button but9; 
    Button but10; 
    Button but11; 
    Button but12; 
    Button but13; 
    Button but14; 
    Button but15; 
    Button but16; 
    // other buttons 
    Button butser; 
    Button butnext; 
    Button butprev; 
    Button butref; 
    Button buth; 
    Button butg; 
    Button but1f; 
    Button butnej; 
    Button butab; 
    // tabpanes 
    TabPane tabpane1; 
    Tab tab1; 
    Tab tab2; 
    Tab tab3; 
    Tab tab4; 
    Tab tab5; 
    Tab tab6; 
    Tab tab7; 
    Tab tab8; 
    Tab tab9; 
    // wabpanes 
    WebView web1; 
    WebView web2; 
    WebView web3; 
    WebView web4; 
    WebView web5; 
    WebView web6; 
    WebView web7; 
    WebView web8; 
    WebView web9; 
    //other window (chooser) 
    @FXML 
    Label que; 
    @FXML 
    Button tab1b; 
    Button tab2b; 
    Button tab3b; 
    Button tab4b; 
    Button tab5b; 
    Button tab6b; 
    Button tab7b; 
    Button tab8b; 
    Button tab9b; 
    @FXML 
    AnchorPane panoo; 
@FXML 
    private void searchButton (ActionEvent evt) throws IOException { 

     Stage stage = new Stage(); 
      Parent root = FXMLLoader.load(getClass().getResource("Choose.fxml")); 
       Scene scene = new Scene(root); 
       stage.setScene(scene); 
       stage.show(); 

     text11.setOnKeyTyped(new EventHandler<KeyEvent>(){ 
      public void hendeller (KeyEvent evty) throws IOException{ 
       if (evty.getCode() == KeyCode.ENTER){ 
     Stage stage = new Stage(); 
      Parent root = FXMLLoader.load(getClass().getResource("Choose.fxml")); 
       Scene scene = new Scene(root); 
       stage.setScene(scene); 
       stage.show(); 
       } 
      } 

      @Override 
      public void handle(KeyEvent t) { 

      } 


     }); 
    } 
    @FXML 
    private void tabfirst (ActionEvent ee) throws IOException { // for tha Chooser frame text. 

       String hh = text11.getText(); 
       Socket socket = new Socket(); 

     try { 
       web1.setVisible(true); 
      //open cursor 
      panoo.setCursor(Cursor.WAIT); 
      que.setCursor(Cursor.WAIT); 
      //add 
      ancpa.setCursor(Cursor.WAIT); 
      web1.setCursor(Cursor.WAIT); 
      web2.setCursor(Cursor.WAIT); 
      web3.setCursor(Cursor.WAIT); 
      web4.setCursor(Cursor.WAIT); 
      web5.setCursor(Cursor.WAIT); 
      web6.setCursor(Cursor.WAIT); 
      web7.setCursor(Cursor.WAIT); 
      web8.setCursor(Cursor.WAIT); 
      web9.setCursor(Cursor.WAIT); 
      //do work 
      URL url = new URL (hh); 
      url.getContent(); 
      WebEngine myWebEngine = web1.getEngine(); 
      myWebEngine.load(url.toExternalForm()); 
      //close the window chooser 
      Stage stage = new Stage(); 
       Parent root = FXMLLoader.load(getClass().getResource("Choose.fxml")); 
       Scene scene = new Scene(root); 
      stage.setOnCloseRequest(new EventHandler<WindowEvent>() { 
        @Override public void handle(WindowEvent t) { } }); 
      //close cursor 
      ancpa.setCursor(Cursor.DEFAULT); 
      web1.setCursor(Cursor.DEFAULT); 
      web2.setCursor(Cursor.DEFAULT); 
      web3.setCursor(Cursor.DEFAULT); 
      web4.setCursor(Cursor.DEFAULT); 
      web5.setCursor(Cursor.DEFAULT); 
      web6.setCursor(Cursor.DEFAULT); 
      web7.setCursor(Cursor.DEFAULT); 
      web8.setCursor(Cursor.DEFAULT); 
      web9.setCursor(Cursor.DEFAULT); 
     } 
     catch (IOException e){ 
      final Stage stg = new Stage();   
      stg.initModality(Modality.APPLICATION_MODAL); 
      stg.initOwner(stg); 
      stg.setTitle("Cannot connect to the internet /n Please Verify your connection internet"); 
      labelno.setText("Cannot connect to the internet..."); 
      //close chooser 
      Stage stage = new Stage(); 
      Parent root = FXMLLoader.load(getClass().getResource("Choose.fxml")); 
      stage.setOnCloseRequest(new EventHandler<WindowEvent>() { 
        @Override public void handle(WindowEvent t) { } }); 

      //set cursor 
      ancpa.setCursor(Cursor.DEFAULT); 
      web1.setCursor(Cursor.DEFAULT); 
      web2.setCursor(Cursor.DEFAULT); 
      web3.setCursor(Cursor.DEFAULT); 
      web4.setCursor(Cursor.DEFAULT); 
      web5.setCursor(Cursor.DEFAULT); 
      web6.setCursor(Cursor.DEFAULT); 
      web7.setCursor(Cursor.DEFAULT); 
      web8.setCursor(Cursor.DEFAULT); 
      web9.setCursor(Cursor.DEFAULT); 
     } finally{ 
      try{ socket.close(); } catch (Exception e){ } 
      } 

    } 
    @FXML 
    private void err (ActionEvent eer) { 
       web1.setVisible(true); 
       ancpa.setCursor(Cursor.WAIT); 
    } 

    @Override 
    public void initialize(URL url, ResourceBundle rb) { 

     } 

} 

這裏是StuckTrace

ant -f C:\\Users\\Midoo\\Documents\\NetBeansProjects\\AmNet23 jfxsa-run 
init: 
Deleting: C:\Users\Midoo\Documents\NetBeansProjects\AmNet23\build\built-jar.properties 
deps-jar: 
Updating property file: C:\Users\Midoo\Documents\NetBeansProjects\AmNet23\build\built-jar.properties 
compile: 
Detected JavaFX Ant API version 1.2 
jfx-deployment: 
jar: 
Copying 12 files to C:\Users\Midoo\Documents\NetBeansProjects\AmNet23\dist\run1416917689 
jfx-project-run: 
Executing C:\Users\Midoo\Documents\NetBeansProjects\AmNet23\dist\run1416917689\AmNet23.jar using platform C:\Program Files\Java\jdk1.7.0_65\jre/bin/java 
java.lang.IllegalAccessException: Class javafx.fxml.FXMLLoader$ValueElement can not access a member of class amnet23.FXMLDocumentController with modifiers "" 
file:/C:/Users/Midoo/Documents/NetBeansProjects/AmNet23/dist/run1416917689/AmNet23.jar!/amnet23/WorkSpace.fxml:15 
    at javafx.fxml.FXMLLoader$ValueElement.processValue(FXMLLoader.java:664) 
    at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:575) 
    at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2356) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2172) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2069) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2830) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2809) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2795) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2782) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2771) 
    at amnet23.AmNet23.start(AmNet23.java:23) 
    at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319) 
    at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:219) 
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:182) 
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:179) 
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76) 
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
    at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17) 
    at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67) 
    at java.lang.Thread.run(Thread.java:745) 

Exception in Application start method 
java.lang.reflect.InvocationTargetException 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
    at java.lang.reflect.Method.invoke(Method.java:606) 
    at com.javafx.main.Main.launchApp(Main.java:698) 
    at com.javafx.main.Main.main(Main.java:871) 
Caused by: 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:745) 
Caused by: java.lang.RuntimeException: java.lang.IllegalAccessException: Class javafx.fxml.FXMLLoader$ValueElement can not access a member of class amnet23.FXMLDocumentController with modifiers "" 
    at javafx.fxml.FXMLLoader$ValueElement.processValue(FXMLLoader.java:664) 
    at javafx.fxml.FXMLLoader$ValueElement.processStartElement(FXMLLoader.java:575) 
    at javafx.fxml.FXMLLoader.processStartElement(FXMLLoader.java:2356) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2172) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2069) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2830) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2809) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2795) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2782) 
    at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2771) 
    at amnet23.AmNet23.start(AmNet23.java:23) 
    at com.sun.javafx.application.LauncherImpl$5.run(LauncherImpl.java:319) 
    at com.sun.javafx.application.PlatformImpl$5.run(PlatformImpl.java:219) 
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:182) 
    at com.sun.javafx.application.PlatformImpl$4$1.run(PlatformImpl.java:179) 
    at java.security.AccessController.doPrivileged(Native Method) 
    at com.sun.javafx.application.PlatformImpl$4.run(PlatformImpl.java:179) 
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76) 
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
    at com.sun.glass.ui.win.WinApplication.access$100(WinApplication.java:17) 
    at com.sun.glass.ui.win.WinApplication$3$1.run(WinApplication.java:67) 
    ... 1 more 
Caused by: java.lang.IllegalAccessException: Class javafx.fxml.FXMLLoader$ValueElement can not access a member of class amnet23.FXMLDocumentController with modifiers "" 
    at sun.reflect.Reflection.ensureMemberAccess(Reflection.java:109) 
    at java.lang.reflect.AccessibleObject.slowCheckMemberAccess(AccessibleObject.java:261) 
    at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:253) 
    at java.lang.reflect.Field.set(Field.java:738) 
    at javafx.fxml.FXMLLoader$ValueElement.processValue(FXMLLoader.java:662) 
    ... 21 more 
Java Result: 1 
Deleting directory C:\Users\Midoo\Documents\NetBeansProjects\AmNet23\dist\run1416917689 
jfxsa-run: 
BUILD SUCCESSFUL (total time: 6 seconds) 

所以。我不理解所造成的這個問題什麼請任何人可以幫助我,並提前致謝:)

+0

你能在控制器類和相應的FXML元素中顯示字段聲明嗎? – 2015-01-26 18:27:51

+0

對不起@James_D我不明白你! – APro 2015-01-26 20:58:10

+0

你不明白哪一點?你有一個FXML文件,你有一個控制器類。請更新您的問題以顯示您在控制器類中聲明的字段。還請在FXML中顯示應該映射到這些字段的相應元素。當FXMLLoader嘗試初始化控制器字段時會產生錯誤:類javafx.fxml.FXMLLoader $ ValueElement無法訪問具有修飾符的類amnet23.FXMLDocumentController的成員「」 – 2015-01-26 21:13:08

回答

1

你沒有顯示的FXML,所以這是一個猜測,但你的控制器中的大部分字段不是@FXML -annotated,似乎在其他地方初始化。所以我懷疑FXMLLoader正在嘗試注入一個(或多個)沒有@FXML註釋的字段。您需要註釋從FXML文件注入的所有字段。

+0

謝謝sooooooo:D – APro 2015-01-27 20:47:20

相關問題