2017-12-29 17 views
0

"icon.png"파일이 클래스와 같은 폴더에 있습니다. 하지만 난 그냥 (새로운 Image ("icon.png")) 다음 java.lang.IllegalArgumentException 말한다 : 잘못된 URL : 잘못된 URL 또는 리소스를 찾을 수 없습니다. 하지만 이제 getClass(). getResource를 추가 한 후 ...이 오류가 발생합니다. 여기스테이지 아이콘 javafx에서 NullPointerException 오류가 발생했습니다.

package application; 

import javafx.application.Application; 
import javafx.fxml.FXMLLoader; 
import javafx.stage.Stage; 
import javafx.scene.Parent; 
import javafx.scene.Scene; 
import javafx.scene.image.Image; 

public class Main extends Application { 
    public void start(Stage primaryStage) { 
     try { 
      Parent root = FXMLLoader.load(getClass().getResource("NewFile.fxml")); 
      Scene scene = new Scene(root); 
      primaryStage.setResizable(false); 
      scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm()); 
      primaryStage.setScene(scene); 
      primaryStage.getIcons().add(new Image(getClass().getResource("icon.png").toExternalForm())); 
      primaryStage.show(); 
     } 
     catch(Exception e) { 
      e.printStackTrace(); 
     } 
    } 

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

그리고 오류입니다 :

java.lang.NullPointerException 
    at application.Main.start(Main.java:19) 
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(Unknown Source) 
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$11(Unknown Source) 
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$9(Unknown Source) 
    at java.base/java.security.AccessController.doPrivileged(Native Method) 
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(Unknown Source) 
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source) 
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method) 
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source) 
    at java.base/java.lang.Thread.run(Unknown Source) 

가 그것을 해결하기 위해 도와주세요 여기 내 코드입니다. 미리 감사드립니다!

+0

가능한 중복 된 [I 고칠 어떻게 NullPointerException이, 그리고 무엇?] (https://stackoverflow.com/questions/218384/what-is-a-nullpointerexception-and-how- do-i-fix-it) – khelwood

+0

리소스 폴더의 이미지가 fxml 및 css 파일과 함께 있습니까? – yarwest

+0

예 이미지가 fxml 및 css 파일과 함께 동일한 폴더에 있습니다 –

답변

0

NullPointerException이 오류로 인해 location of your image is not in the proper position에 발생하여 프로젝트 건설 우리에게 보여 게시물을 편집 할 수 있습니다 존재하지있는 뭔가를 참조
이 같은 뭔가를해야만 작동하도록해야합니다! 의

enter image description here

+0

도움을 주셔서 대단히 감사합니다! –

관련 문제