我正在尝试在Android中使用ehCache,并收到以下错误
java.lang.ExceptionInInitializerError
at net.sf.ehcache.EhcacheDefaultClassLoader.getInstance(EhcacheDefaultClassLoader.java:29)
at net.sf.ehcache.config.Configuration.(Configuration.java:208)
at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:152)
at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:103)
at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:140)
at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:892)
at net.sf.ehcache.CacheManager.create(CacheManager.java:873)
at net.sf.ehcache.CacheManager.getInstance(CacheManager.java:907)
Caused by: java.lang.NullPointerException: parentLoader == null && !nullAllowed
at java.lang.ClassLoader.(ClassLoader.java:210)
at java.lang.ClassLoader.(ClassLoader.java:202)
at net.sf.ehcache.EhcacheDefaultClassLoader.(EhcacheDefaultClassLoader.java:35)
at net.sf.ehcache.EhcacheDefaultClassLoader.(EhcacheDefaultClassLoader.java:26)
at net.sf.ehcache.EhcacheDefaultClassLoader.getInstance(EhcacheDefaultClassLoader.java:29)
at net.sf.ehcache.config.Configuration.(Configuration.java:208)
at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:152)
at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:103)
at net.sf.ehcache.config.ConfigurationFactory.parseConfiguration(ConfigurationFactory.java:140)
at net.sf.ehcache.CacheManager.newInstance(CacheManager.java:892)
at net.sf.ehcache.CacheManager.create(CacheManager.java:873)
at net.sf.ehcache.CacheManager.getInstance(CacheManager.java:907)
这是我尝试初始化的代码
private static Cache getCache(String cacheName) throws IllegalStateException{
CacheManager cacheManager = CacheManager.getInstance();
Cache cache;
if(!cacheManager.cacheExists(cacheName)) {
cacheManager.addCache(cacheName);
}
cache = cacheManager.getCache(cacheName);
return cache;
}
看起来EHCache无法在android中工作?有人可以对此有所启发吗?
收到错误消息后,我还将ehcache.xml放在了res / xml /中,并进行了一些配置
ehcache.xml