2015-11-24 22 views
1

我在編譯時遇到這個錯誤,我不知道爲什麼。錯誤日誌也沒有說明太多。已經搜索了其他答案,它們都屬於我沒有使用或者推薦使用的框架,以確保文件的名稱與類的名稱相同(都稱爲「FolderSyncer4」)。參考代碼:線程「main」中的異常java.lang.ClassNotFoundException:sample.Main - 爲什麼?

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 
+4

你告訴IntelliJ運行'sample.Main'類。但是你的班級被命名爲'sample.FolderSyncer4'。更改要在IntelliJ運行配置中運行的類的名稱。 – Jesper

+0

@Jesper爲什麼不作爲回答發佈? –

回答

4

java -jar xxx.jar sample.FolderSyncer4應該工作。看來你用sample.Main來代替。

相關問題