2017-02-26 10 views
-1

ユーザー入力を受け付けてファイルに保存するJavaFXアプリケーションを開発中です。シーンをスタイリングするために、私はCSSを使用しています。JavaFX jarの実行によりinvocationtargetexceptionがスローされる

私が使用しているIDEは、それがにInvocationTargetExceptionをスローし、私はjarファイルを実行しようとしたときはいつでも、私はjarファイル

These are all the files inside the project directory

public void start(Stage primaryStage) throws Exception { 

    String[] noti = {"Loading...","Verifying user...","Gathering info...","Success"}; 

    primaryStage.initStyle(StageStyle.UNDECORATED); 
    VBox root = new VBox(); 
    Scene scene = new Scene(root, 1100, 650); 

    Label label = new Label("Loading..."); 


    ProgressBar progressBar = new ProgressBar(0.1); 


    Thread thr = new Thread(new Runnable() { 
     @Override 
     public void run() { 

      try{ 

       Thread.sleep(1500); 
       progressBar.setProgress(0.2); 

      }catch(Exception e){} 

     } 

    }); 



    primaryStage.setScene(scene); 
    root.getChildren().addAll(progressBar, label); 
    scene.getStylesheets().add(getClass().getResource("view/Main.CSS").toExternalForm()); 
    File file = new File("C:\\Users\\SVNPC\\Documents\\NetBeansProjects\\portee\\TEST_1"); 

    if(!file.exists()){ 
     file.mkdir();   
    } 

    file = new File("C:\\Users\\SVNPC\\Documents\\NetBeansProjects\\portee\\TEST_1\\core.txt"); 


    if(!file.exists() && !file.isDirectory()){ 


     // Create the file and Fill it with user data 


    } 

    else{ 



    } 

    primaryStage.show(); 
    thr.start(); 

} 

にすべてのクラスとファイルを詰め使用してNetBeansのです。 私はJavaFXのに新しいですし、私はこれらの多くの例外

This happened when I tried to run the JAR

+0

Splash.javaファイルのコードを投稿してください。129行目にNullPointerExceptionがあります。 –

+0

scene.getStylesheets()。(getClass()。getResource( "view/Main.CSS")。toExternalForm()); これは私が李に持っているものです:129 –

+0

シーンはnullではありませんか?または、getStylesheetsがnullではありませんか? –

答えて

0

あなたのエラーがSplash.javaファイルの行129にNullPointerExceptionあるを投げるために瓶を引き起こしているものは考えています。あなたは私にその行にあなたのコードを教えて

は次のとおりです。

scene.getStylesheets().add(getClass().getResource("view/Main.CSS").toExternalForm()); 

だから、あなたが代入する前にこのチェックを追加する必要があります。

あなたはシーンを保証することができますが、この行に持っているので、nullではない:

Scene scene = new Scene(root, 1100, 650); 

ので、チェックはなります:

if (scene.getStylesheets() != null && getClass() != null 
&& getClass().getResource("view/Main.CSS") != null) { 
    scene.getStylesheets().add(
     getClass().getResource("view/Main.CSS").toExternalForm()); 
} 

ヌルオブジェクトのプロパティを使用しようとすると、NullPointerExceptionが上昇するためです。

+0

JARファイルはcharm broのように動作しますが、CSSファイルがまったく読み込まれないという問題があります。シーンはカスタムスタイリングなしで表示されています –

関連する問題