java.lang.ExceptionInInitializerError when creating instance of EHCache in android

后端 未结 1 602
后悔当初
后悔当初 2021-01-17 03:06

I am trying to use ehCache in Android, and getting the following error

java.lang.ExceptionInInitializerError
    at net.sf.ehcache.EhcacheDefaultClassLoader.         


        
相关标签:
1条回答
  • 2021-01-17 03:41

    Ehcache is not able to locate the ehcach.xml file. It has no idea about res/xml folder.

    So try to configure your cache programmatically in this way (ehcache 2.10):

    // create default CacheManager
    Configuration config = new Configuration();
    config.setName("Mngmt");
    // [...]
    CacheManager cacheManager = CacheManager.create(config);
    
    int maxEntriesLocalHeap = 100;
    String cachName = "cacheName";
    Cache cache = new Cache(
      new CacheConfiguration(cachName, maxEntriesLocalHeap)
        .memoryStoreEvictionPolicy(MemoryStoreEvictionPolicy.LFU)
        .eternal(false)
        .timeToLiveSeconds(120)
        .timeToIdleSeconds(60)
        .diskExpiryThreadIntervalSeconds(0));
    cacheManager.addCache(cache);
    

    More Information you will find here: Creating Caches Programmatically

    0 讨论(0)
提交回复
热议问题