我在编译时遇到了这个错误,我不知道为什么。错误日志也没有提供太多信息。已经搜索了其他答案,它们都与我没有使用或建议使用的框架有关,以确保文件的名称与类的名称相同(是的,都名为"FolderSyncer4")。参考代码:
FolderSyncer4.java
package sample;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.DirectoryChooser;
import javafx.stage.Stage;
import java.io.*;
import java.nio.file.Path;
import java.util.LinkedList;
public class FolderSyncer4 extends Application {
final String FOLDER_SYNCER = "FolderSyncer";
Stage theStage;
public static void main(String[] args) {
launch(args);
}
@Override
public void start(Stage primaryStage) throws Exception {
theStage = primaryStage;
//TODO do the FXML stuff, hope this works
//Parent root = FXMLLoader.load(getClass().getResource("FolderSyncerMainWindow.fxml"));
//Display the "Selecting" scene at first
theStage.setTitle(FOLDER_SYNCER);
theStage.show();
}
}
FolderSyncerMainWindowController.java
package sample;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import java.io.IOException;
public class FolderSyncerMainWindowController {
final String FOLDER_SYNCER = "FolderSyncer";
final String BROWSE = "Browse";
final String SOURCE = "Source...";
final String TARGET = "Target...";
final String COMPARE = "Compare";
final String CANCEL = "Cancel";
final String SYNCHRONIZE = "Synchronize";
final String COMPARING = "Comparing, this may take several minutes.";
final String SYNCHRONIZING = "Synchronizing, this may take several minutes.";
final String DONE = "Done.";
public Label sourceLabel = new Label(SOURCE);
}
FolderSyncerMainWindow.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.effect.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.geometry.Insets?>
<?import javafx.scene.layout.GridPane?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.Label?>
<BorderPane prefHeight="574.0" prefWidth="687.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1"
fx:controller="sample.FolderSyncerMainWindowController">
<padding>
<Insets bottom="8.0" left="8.0" right="8.0" top="8.0" />
</padding>
<left>
<HBox prefHeight="492.0" prefWidth="523.0" spacing="8.0" BorderPane.alignment="CENTER">
<children>
<TreeView prefHeight="509.0" prefWidth="321.0" HBox.hgrow="ALWAYS" />
<TreeView prefHeight="509.0" prefWidth="324.0" HBox.hgrow="ALWAYS" />
</children>
</HBox>
</left>
<top>
<VBox prefHeight="47.0" prefWidth="702.0" spacing="8.0" BorderPane.alignment="CENTER">
<children>
<HBox prefHeight="8.0" prefWidth="702.0" spacing="8.0">
<children>
<Label fx:id="sourceLabel" prefHeight="17.0" prefWidth="44.0">
<HBox.margin>
<Insets />
</HBox.margin>
</Label>
<TextField editable="false" prefHeight="25.0" prefWidth="543.0" HBox.hgrow="ALWAYS" />
<Button mnemonicParsing="false" prefHeight="25.0" prefWidth="61.0" text="Browse" />
</children>
<VBox.margin>
<Insets />
</VBox.margin>
</HBox>
<HBox prefHeight="45.0" prefWidth="702.0" spacing="8.0">
<children>
<Label prefHeight="17.0" prefWidth="44.0" text="Target" />
<TextField editable="false" prefHeight="25.0" prefWidth="543.0" HBox.hgrow="ALWAYS" />
<Button mnemonicParsing="false" prefHeight="25.0" prefWidth="61.0" text="Browse" />
</children>
</HBox>
</children>
<BorderPane.margin>
<Insets bottom="8.0" />
</BorderPane.margin>
</VBox>
</top>
<right>
<GridPane prefHeight="492.0" prefWidth="140.0" BorderPane.alignment="CENTER">
<columnConstraints>
<ColumnConstraints halignment="CENTER" hgrow="SOMETIMES" minWidth="10.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
<effect>
<DropShadow />
</effect>
<BorderPane.margin>
<Insets left="8.0" />
</BorderPane.margin>
<children>
<Button fx:id="compareButton" mnemonicParsing="false" text="Compare" />
<Button fx:id="synchronizeButton" mnemonicParsing="false" text="Synchronize" GridPane.rowIndex="1" />
</children>
</GridPane>
</right>
</BorderPane>
错误日志:
Exception in thread "main" java.lang.ClassNotFoundException: sample.Main
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:122)
Process finished with exit code 1
java -jar xxx.jar sample.FolderSyncer4
应该可以工作。似乎您使用了sample.Main
。