首页 > 解决方案 > 错误:错误:无法找到或加载主类 neon.Main

问题描述

我正在编写一个应用程序,但我收到标题中命名的错误消息。在 src 文件夹中是软件包 neon 下的 Main.java 类。包 neon.friends 包含 Friends.fxml。并且包 neon.views 包含 MainItemsController.java、MainItems.fxml 和 MainView.fxml。

下面是主类的代码:

    package neon;

import java.io.IOException;


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

public class Main extends Application {

private Stage primaryStage;
private static  BorderPane mainLayout;

@Override
public void start(Stage primaryStage) throws IOException {
    this.primaryStage = primaryStage;
    this.primaryStage.setTitle("Neon");
    showMainView();
    showMainItems();
}

private void showMainView() throws IOException{
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(Main.class.getResource("view/MainView.fxml"));
    mainLayout = loader.load();
    Scene scene = new Scene(mainLayout);
    primaryStage.setScene(scene);
    primaryStage.show();
}

private void showMainItems() throws IOException{
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(Main.class.getResource("view/MainItems.fxml"));
    BorderPane mainItems = loader.load();
    mainLayout.setCenter(mainItems);
}

public static void showFriends() throws IOException{
    FXMLLoader loader = new FXMLLoader();
    loader.setLocation(Main.class.getResource("friends/Friends.fxml"));
    BorderPane friends = loader.load();
    mainLayout.setCenter(friends);
}

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

标签: javajavafx

解决方案


推荐阅读