java - How to load resources in an external self-made library? -


i'm working on java fxml application using netbeans. structuring purpose want reusable code in external selfmade library (just netbeans java project).

i want library code load given fxml views dynamically using like:

class loader {     public static void load(stage stage, string view) {         parent root = fxmlloader.load(loader.class.getclass().getresource(view);         scene scene = new scene(root);         stage.setscene(scene);         stage.show();     } } 

main class in basic fxml application:

class main extends application {      public static void main(string[] args) {         launch(args);     }      @override     public void start(stage stage) throws exception, nullpointerexception {         loader.load(stage, "fxmldocument.fxml");     } } 

but fxml view file located in bacis fxml application project (not external library project code placed). i'm not experienced kind of advanced java stuff, guess it's classpath problem.

the error triggered getresource() line:

exception in application start method java.lang.reflect.invocationtargetexception     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:483)     @ com.sun.javafx.application.launcherimpl.launchapplicationwithargs(launcherimpl.java:367)     @ com.sun.javafx.application.launcherimpl.launchapplication(launcherimpl.java:305)     @ sun.reflect.nativemethodaccessorimpl.invoke0(native method)     @ sun.reflect.nativemethodaccessorimpl.invoke(nativemethodaccessorimpl.java:62)     @ sun.reflect.delegatingmethodaccessorimpl.invoke(delegatingmethodaccessorimpl.java:43)     @ java.lang.reflect.method.invoke(method.java:483)     @ sun.launcher.launcherhelper$fxhelper.main(launcherhelper.java:767) caused by: java.lang.runtimeexception: exception in application start method     @ com.sun.javafx.application.launcherimpl.launchapplication1(launcherimpl.java:894)     @ com.sun.javafx.application.launcherimpl.access$000(launcherimpl.java:56)     @ com.sun.javafx.application.launcherimpl$1.run(launcherimpl.java:158)     @ java.lang.thread.run(thread.java:744) caused by: java.lang.nullpointerexception: location required.     @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:3223)     @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:3191)     @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:3164)     @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:3140)     @ javafx.fxml.fxmlloader.loadimpl(fxmlloader.java:3120)     @ javafx.fxml.fxmlloader.load(fxmlloader.java:3113) ..... 

just needed add package name filepath loader.load(stage, "package/fxmldocument.fxml"); ....


Comments

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -