I study an example using internationalization using the ResourceBundle and ListResourceBundle .
The example demonstrates the use of resource bundles under the SampleRB family name.
After compiling, I constantly get the error:
ΠΠ½Π³Π»ΠΈΠΉΡΠΊΠ°Ρ Π²Π΅ΡΡΠΈΡ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ: Exception in thread "main" java.lang.NullPointerException at java.util.ListResourceBundle.loadLookup(ListResourceBundle.java:202) at java.util.ListResourceBundle.handleGetObject(ListResourceBundle.java:130) at java.util.ResourceBundle.getObject(ResourceBundle.java:441) at java.util.ResourceBundle.getString(ResourceBundle.java:407) at LRBDemo.LRBDemo.main(LRBDemo.java:12) The program itself consists of the LRBDemo class with the launching method main:
public class LRBDemo { public static void main(String[] args) { // Π·Π°Π³ΡΡΠ·ΠΈΡΡ ΠΊΠΎΠΌΠΏΠ»Π΅ΠΊΡ ΡΠ΅ΡΡΡΡΠΎΠ² ΠΏΠΎ ΡΠΌΠΎΠ»ΡΠ°Π½ΠΈΡ ResourceBundle rd = ResourceBundle.getBundle("LRBDemo.SampleRB"); System.out.println("ΠΠ½Π³Π»ΠΈΠΉΡΠΊΠ°Ρ Π²Π΅ΡΡΠΈΡ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ: "); System.out.println("Π‘ΡΡΠΎΠΊΠ° ΠΏΠΎ ΠΊΠ»ΡΡΡ Title: " + rd.getString("title")); System.out.println("Π‘ΡΡΠΎΠΊΠ° ΠΏΠΎ ΠΊΠ»ΡΡΡ StopText: " + rd.getString("StopText")); System.out.println("Π‘ΡΡΠΎΠΊΠ° ΠΏΠΎ ΠΊΠ»ΡΡΡ StartText: " + rd.getString("StartText")); // Π·Π°Π³ΡΡΠ·ΠΈΡΡ ΠΊΠΎΠΌΠΏΠ»Π΅ΠΊΡ ΡΠ΅ΡΡΡΡΠΎΠ² Π΄Π»Ρ ΠΏΠΎΠ΄Π΄Π΅ΡΠΆΠΊΠΈ Π½Π΅ΠΌΠ΅ΡΠΊΠΎΠ³ΠΎ ΡΠ·ΡΠΊΠ° rd = ResourceBundle.getBundle("LRBDemo.SampleRBde", Locale.GERMAN); System.out.println("\nΠΠ΅ΠΌΠ΅ΡΠΊΠ°Ρ Π²Π΅ΡΡΠΈΡ ΠΏΡΠΎΠ³ΡΠ°ΠΌΠΌΡ: "); System.out.println("Π‘ΡΡΠΎΠΊΠ° Π΄Π»Ρ ΠΊΠ»ΡΡΠ° Title: " + rd.getString("title")); System.out.println("Π‘ΡΡΠΎΠΊΠ° ΠΏΠΎ ΠΊΠ»ΡΡΡ StopText: " + rd.getString("StopText")); System.out.println("Π‘ΡΡΠΎΠΊΠ° ΠΏΠΎ ΠΊΠ»ΡΡΡ StartText: " + rd.getString("StartText")); } } SampleRB class with English language support:
public class SampleRB extends ListResourceBundle { protected Object[][] getContents() { Object[][] resources = new Object[3][2]; resources[0][0] = "title"; resources[0][1] = "MyProgram"; resources[1][0] = "StopText"; resources[1][1] = "Stop"; resources[1][0] = "StartText"; resources[2][1] = "Start"; return resources; } } And class SampleRBde with German support:
public class SampleRBde extends ListResourceBundle { protected Object[][] getContents() { Object[][] resources = new Object[3][2]; resources[0][0] = "title"; resources[0][1] = "Mein Programm"; resources[1][0] = "StopText"; resources[1][1] = "Anschlag"; resources[2][0] = "StartText"; resources[2][1] = "Anfang"; return resources; } } The code itself does not display errors, but if I register in the LRBDemo class , instead of the string ResourceBundle rd = ResourceBundle.getBundle("LRBDemo.SampleRB") thus ResourceBundle rd = ResourceBundle.getBundle("SampleRB") and instead of rd = ResourceBundle.getBundle("LRBDemo.SampleRBde", Locale.GERMAN); ResourceBundle rd = ResourceBundle.getBundle("SampleRB") and instead of rd = ResourceBundle.getBundle("LRBDemo.SampleRBde", Locale.GERMAN); ResourceBundle rd = ResourceBundle.getBundle("SampleRB") and instead of rd = ResourceBundle.getBundle("LRBDemo.SampleRBde", Locale.GERMAN); so rd = ResourceBundle.getBundle("SampleRBde", Locale.GERMAN); , that is, I remove the class package, then I get the output:
Exception in thread "main" java.util.MissingResourceException: Can't find bundle for base name SampleRB, locale ru_RU at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1564) at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1387) at java.util.ResourceBundle.getBundle(ResourceBundle.java:773) at LRBDemo.LRBDemo.main(LRBDemo.java:9) The structure of my project:
I would be grateful for the advice on how to remove the errors and finally output the result.


