簡體   English   中英

Netbeans 找不到 JavaFX 應用類

[英]Netbeans cannot find JavaFX Application classes

I'm trying to run some code snippets from my Java class in netbeans, and netbeans consistently cannot seem to recognise the application classes(no matter the code snippet) and throws up an empty Browse JavaFX Application Classes window whenever I try to build or run應用程序。

這是我目前正在嘗試運行的代碼:

package examplereaderusingfilereader;

import java.io.Reader;
import java.io.FileReader;

public class ExampleReaderUsingFileReader {
    public static void main(String[] args) {
    //creates an array of character
    char[] array = new char[100];
    try {
        //creates a reader using the FileReader
        Reader input = new FileReader("input.txt");
        //checks if reader is ready
        System.out.println("Is there data in the stream? " + input.ready());
        //Reads characters
        input.read(array);
        System.out.println("Data in the stream");
        System.out.println(array);
        //closes the reader
        input.close();
    } catch(Exception e) {
        e.getStackTrace();
        }
    }
}

嘗試添加e.printStackTrace(); 也許你沒有這樣的文件或目錄

您需要做的就是使用“應用程序”擴展您的主 Class。 像這樣修改你的主 Class 和主 function

public class ExampleReaderUsingFileReader extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception{
         // Your snippet code here 

        Scene scene = new Scene(new AnchorPane()); 
        //create your fxml file on the same folder of main if not exist
        Parent root = FXMLLoader.load(getClass().getResource("sample.fxml"));
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM