MissingResourceException: Can't find bundle for base name resources.controls.controls_res, locale en
Не могу понять в чем проблема, почему он ругается и не может найти locale en. Может проблема с путями или названиями boundle?
Проект legacy, написан 15 лет назад, был раньше на Ant, сейчас как перевел на Gradle, появилась данная ошибка. На Ant собирается без проблем.
P.S.Строки на которые ссылаются ошибки я отметил отдельно в классах.
Ошибки:
java.lang.ExceptionInInitializerError
at org.opensourcephysics.controls.OSPLog.<init>(OSPLog.java:937)
at org.opensourcephysics.controls.OSPLog.getOSPLog(OSPLog.java:124)
at org.opensourcephysics.cabrillo.tracker.Tracker.loadPreferences(Tracker.java:1391)
at org.opensourcephysics.cabrillo.tracker.Tracker.<clinit>(Tracker.java:251)
Caused by: java.util.MissingResourceException: Can't find bundle for base name org.opensourcephysics.resources.controls.controls_res, locale en
Caused by: java.util.MissingResourceException: Can't find bundle for base name org.opensourcephysics.resources.controls.controls_res, locale en
at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1581)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1396)
at java.util.ResourceBundle.getBundle(ResourceBundle.java:854)
at org.opensourcephysics.controls.ControlsRes.<clinit>(ControlsRes.java:55)
... 4 more
Caused by: java.lang.NullPointerException
at java.util.Properties$LineReader.readLine(Properties.java:434)
at java.util.Properties.load0(Properties.java:353)
at java.util.Properties.load(Properties.java:341)
at java.util.PropertyResourceBundle.<init>(PropertyResourceBundle.java:138)
at org.opensourcephysics.resources.controls.controls_res.<init>(controls_res.java:32)
at org.opensourcephysics.resources.controls.controls_res.<init>(controls_res.java:23)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at java.util.ResourceBundle$Control.newBundle(ResourceBundle.java:2662)
Caused by: java.lang.NullPointerException
at java.util.ResourceBundle.loadBundle(ResourceBundle.java:1518)
at java.util.ResourceBundle.findBundle(ResourceBundle.java:1482)
at java.util.ResourceBundle.findBundle(ResourceBundle.java:1436)
at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1370)
... 6 more
Exception in thread "main"
Execution failed for task ':Tracker.main()'.
Как видно из логов, все ошибки вызываются из-за того что он не может найти locale en.
Класс controls_res:
public class controls_res extends PropertyResourceBundle {
// relative path to strings
static String res = "controls_res.properties"; //$NON-NLS-1$
/**
* Constructor tools
* @throws IOException
*/
public controls_res() throws IOException {
this(controls_res.class.getResourceAsStream(res)); 23 СТРОКА!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
/**
* Constructor tools
* @param stream
* @throws IOException
*/
public controls_res(InputStream stream) throws IOException {
super(stream); // 32 СТРОКА!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
}
}
Класс controls_res_en:
/**
* English resource loader for OSP controls class. Resource strings are obtained from superclass.
* @author Wolfgang Christian
*/
public class controls_res_en extends controls_res {
/**
* Constructor controls_res_en
* @throws IOException
*/
public controls_res_en() throws IOException {
super();
}
}
Класс ControlsRes:
public class ControlsRes {
// static constants for speed
public static String ANIMATION_NEW;
public static String ANIMATION_INIT;
public static String ANIMATION_STEP;
public static String ANIMATION_RESET;
public static String ANIMATION_START;
public static String ANIMATION_STOP;
public static String ANIMATION_RESET_TIP;
public static String ANIMATION_INIT_TIP;
public static String ANIMATION_START_TIP;
public static String ANIMATION_STOP_TIP;
public static String ANIMATION_NEW_TIP;
public static String ANIMATION_STEP_TIP;
public static String CALCULATION_CALC;
public static String CALCULATION_RESET;
public static String CALCULATION_CALC_TIP;
public static String CALCULATION_RESET_TIP;
public static String XML_NAME;
public static String XML_VALUE;
static final String BUNDLE_NAME = "org.opensourcephysics.resources.controls.controls_res"; //$NON-NLS-1$
static ResourceBundle res;
// private constructor because all methods are static
private ControlsRes() {}
static {
String language = Locale.getDefault().getLanguage();
Locale resourceLocale = Locale.ENGLISH;
for(Locale locale : OSPRuntime.getInstalledLocales()) {
if(locale.getLanguage().equals(language)) {
resourceLocale = locale;
break;
}
}
res = ResourceBundle.getBundle(BUNDLE_NAME, resourceLocale); // 55 СТРОКА!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
setLocalStrings();
}
private static String getString(final ResourceBundle bundle, final String key) {
try {
return bundle.getString(key);
} catch(final MissingResourceException ex) {
return '|'+key+'|';
}
}
public static void setLocale(Locale locale) {
res = ResourceBundle.getBundle(BUNDLE_NAME, locale);
setLocalStrings();
}
/**
* Gets the localized value of a string. If no localized value is found, the
* key is returned surrounded by exclamation points.
*
* @param key the string to localize
* @return the localized string
*/
static public String getString(String key) {
try {
return res.getString(key);
} catch(MissingResourceException ex) {
return "!"+key+"!"; //$NON-NLS-1$ //$NON-NLS-2$
}
}
/**
* Gets the local strings. Static strings are used for speed to avoid having to call the resource object.
*/
private static void setLocalStrings() {
ANIMATION_NEW = getString(res, "ANIMATION_NEW"); //$NON-NLS-1$
ANIMATION_INIT = getString(res, "ANIMATION_INIT"); //$NON-NLS-1$
ANIMATION_STEP = getString(res, "ANIMATION_STEP"); //$NON-NLS-1$
ANIMATION_RESET = getString(res, "ANIMATION_RESET"); //$NON-NLS-1$
ANIMATION_START = getString(res, "ANIMATION_START"); //$NON-NLS-1$
ANIMATION_STOP = getString(res, "ANIMATION_STOP"); //$NON-NLS-1$
ANIMATION_RESET_TIP = getString(res, "ANIMATION_RESET_TIP"); //$NON-NLS-1$
ANIMATION_INIT_TIP = getString(res, "ANIMATION_INIT_TIP"); //$NON-NLS-1$
ANIMATION_START_TIP = getString(res, "ANIMATION_START_TIP"); //$NON-NLS-1$
ANIMATION_STOP_TIP = getString(res, "ANIMATION_STOP_TIP"); //$NON-NLS-1$
ANIMATION_NEW_TIP = getString(res, "ANIMATION_NEW_TIP"); //$NON-NLS-1$
ANIMATION_STEP_TIP = getString(res, "ANIMATION_STEP_TIP"); //$NON-NLS-1$
CALCULATION_CALC = getString(res, "CALCULATION_CALC"); //$NON-NLS-1$
CALCULATION_RESET = getString(res, "CALCULATION_RESET"); //$NON-NLS-1$
CALCULATION_CALC_TIP = getString(res, "CALCULATION_CALC_TIP"); //$NON-NLS-1$
CALCULATION_RESET_TIP = getString(res, "CALCULATION_RESET_TIP"); //$NON-NLS-1$
XML_NAME = getString(res, "XML_NAME"); //$NON-NLS-1$
XML_VALUE = getString(res, "XML_VALUE"); //$NON-NLS-1$
}
}
Ответы (1 шт):
Создал новые пустые файлы и переписал содержимое из тех же самых файлов - проблема ушла. Видимо, кодировку файла сборщики не могли считывать. Как никак, проект legacy, передавался из рук в руки 100 раз.

