java.util.MissingResourceException: Can't find

2019-02-25 04:04发布

问题:

I have an Android app that uses multidex. It is released and has monthly users in the hundreds of thousands. Every so often I will get ExceptionInInitializerError crashes on Crashlytics. I've never been able to reproduce them.

I read that this can be due to multidex and that have multiDexKeepFile file('multidex-config.txt') on my config with a list of classes would help, but it doesn't seem to help, at least not for this resource. This is the content on my multidex-config.txt:

org.eclipse.jetty.http.MimeTypes
org.eclipse.jetty.server.Server
javax.servlet.LocalStrings

Those are all classes for which I've had crashes like this in the past. I'm still waiting to see if some of those are fixed but this one below keeps coming back for sure:

Fatal Exception: java.lang.ExceptionInInitializerError
       at myapp.run(myclass.java:986)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
       at java.lang.Thread.run(Thread.java:761)
Caused by java.util.MissingResourceException: Can't find bundle for base name javax.servlet.LocalStrings, locale it_IT
       at java.util.ResourceBundle.throwMissingResourceException(ResourceBundle.java:1501)
       at java.util.ResourceBundle.getBundleImpl(ResourceBundle.java:1324)
       at java.util.ResourceBundle.getBundle(ResourceBundle.java:723)
       at javax.servlet.GenericServlet.(GenericServlet.java)

So how can I fix this? In this case it seems to be looking for the Italian file, this isn't always the case and I have a lot of users in Italy so I'm not sure why it is only crashing for a few. The resource bundle on Android Studio for LocalStrings only shows a default one, French and Japanese.

Thanks.

回答1:

Make sure you are not missing to add the servlet-api dependency.

If you're using maven make sure this dependency is in your project:

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>3.1.0</version>
</dependency>