This week's book giveaway is in the NodeJS forum.
We're giving away four copies of Serverless Applications with Node.js and have Slobodan Stojanovic & Aleksandar Simovic on-line!
See this thread for details.
Win a copy of Serverless Applications with Node.js this week in the NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Junilu Lacar
  • Paul Clapham
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Ron McLeod
  • Tim Moores
  • salvin francis
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Vijitha Kumara

Program can not access resources?  RSS feed

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class Main extends Application
{
   public static void main(String[] args)
   {
       launch(args);
   }

   private final List<LanguageSelector> languages = new ArrayList<LanguageSelector>() {
       {     add(new LanguageSelector("English", new Locale("en", "EN")));
           add(new LanguageSelector("German", Locale.getDefault()));
       }
   };
 @Override
   public void start(Stage primaryStage) throws Exception
   {

       ChoiceDialog<LanguageSelector> dialog = new ChoiceDialog<>(null, languages);


       Optional<LanguageSelector> pilih = dialog.showAndWait();
       String ww;
      ww=  dialog.getSelectedItem().toString();
       if(ww.equals("English")){
            try {


   ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
   InputStream inputStream = classLoader.getResource("resources.bundles.myapp_en_US.properties").openStream();
   ResourceBundle bundle = new PropertyResourceBundle(inputStream);
   URL fxmlURL = classLoader.getResource("fxml/MainVIew.fxml");
   FXMLLoader loader = new FXMLLoader(fxmlURL, bundle);

   Parent p = loader.load();

   Stage stage = new Stage();
   stage.setScene(new Scene(p));stage.show(); }catch (Exception e){
      e.printStackTrace();
   }
   }else {
   ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
   InputStream inputStream = classLoader.getResource("resources.bundles.myapp_de.properties").openStream();
   ResourceBundle bundle = new PropertyResourceBundle(inputStream);
   URL fxmlURL = classLoader.getResource("fxml/MainVIew.fxml");

   FXMLLoader loader = new FXMLLoader(fxmlURL, bundle);

   Parent p = loader.load();

   Stage stage = new Stage();
   stage.setScene(new Scene(p));stage.show();
}
   }


}
Screenshot-(20190415-015134).jpg
[Thumbnail for Screenshot-(20190415-015134).jpg]
 
Sheriff
Posts: 5813
150
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, remanoo re, and welcome to the Ranch!

First, a few things about your post.  When you post code, please UseCodeTags (that's a link).  Also, be sure to format your code correctly.  And lastly, include the import statements with the code.  All together it should look like this:
Now, why can't your code find the resource bundle?  You need to use slashes between your paths, like this:
If that doesn't work, try an absolute path, like
 
I do some of my very best work in water. Like this tiny ad:
global solutions you can do in your home or backyard
https://coderanch.com/t/708587/global-solutions-home-backyard
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!