Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC 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
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

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]
 
Marshal
Posts: 5995
156
Chrome Eclipse IDE Java Postgres Database Ubuntu 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
 
Willie Smits can speak 40 languages. This tiny ad can speak only one:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!