【问题标题】:Netbeans cannot find JavaFX Application classesNetbeans 找不到 JavaFX 应用程序类
【发布时间】:2021-06-19 16:17:37
【问题描述】:

我正在尝试在 netbeans 中从我的 Java 类运行一些代码 sn-ps,而 netbeans 似乎始终无法识别应用程序类(无论代码是什么 sn-p),并且无论何时都会抛出一个空的 Browse JavaFX Application Classes 窗口我尝试构建或运行应用程序。

这是我目前正在尝试运行的代码:

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();
        }
    }
}

【问题讨论】:

  • 这个问题似乎与JavaFX 无关。您是否尝试过清理和重建项目?
  • 我提到了 JavaFX,因为对于这个特定的类,我仅限于使用 1.8 版的 JavaFX。超出此范围的代码 sn-ps 对我来说毫无用处。我的问题是我无法清理和重建项目,我被这个空的“浏览 JavaFX 应用程序类”窗口阻止了。

标签: java javafx netbeans netbeans-11


【解决方案1】:

尝试添加e.printStackTrace();也许你有没有这样的文件或目录

【讨论】:

    【解决方案2】:

    您需要做的就是使用“应用程序”扩展您的主类。像这样修改你的主类和主函数

    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);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-31
      • 1970-01-01
      • 2023-04-07
      • 1970-01-01
      • 2021-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多