Skip to content
Advertisement

MissingResourceException: Can’t find bundle for base name resources.controls.controls_res, locale en

I can’t understand what the problem is, why he swears and can’t find locale en. Is there a problem with paths or boundle names?

The legacy project, written 15 years ago, used to be in Ant, now it was translated to Gradle, this error has appeared. It builds on Ant without problems.

P.S. I marked the lines to which the errors refer separately in the classes.

ERRORS:

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()'.

As you can see from the logs, all errors are caused due to the fact that it cannot find * 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 STRING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  }

  /**
   * Constructor tools
   * @param stream
   * @throws IOException
   */
  public controls_res(InputStream stream) throws IOException {
    super(stream);  // 32 STRING!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  }
}

Class 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();
  }
}

Class 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 String!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    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$
  }
}

введите сюда описание изображения

enter image description here

Advertisement

Answer

Created new empty files and rewrote the contents from the same files – the problem is gone. Apparently, the file encoding collectors could not read. After all, the legacy project has been passed from hand to hand 100 times.

Advertisement