【问题标题】:java.lang.ExceptionInInitializerError when creating instance of EHCache in android adain在 android adain 中创建 EHCache 实例时出现 java.lang.ExceptionInInitializerError
【发布时间】:2018-08-02 10:32:23
【问题描述】:

我正在尝试在 Android 中使用 ehCache,并收到以下错误

08-01 10:26:11.308 1645-1645/com.example.ehcache.ehcache_test E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.ehcache.ehcache_test, PID: 1645
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.ehcache.ehcache_test/com.example.ehcache.ehcache_test.MainActivity}: net.sf.ehcache.CacheException: java.lang.ExceptionInInitializerError
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2902)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3037)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1797)
    at android.os.Handler.dispatchMessage(Handler.java:106)
    at android.os.Looper.loop(Looper.java:193)
    at android.app.ActivityThread.main(ActivityThread.java:6642)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)

这是我尝试初始化的代码

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        CacheManager manager = CacheManager.getInstance();

        try {
            manager.addCache("myCache");
            Cache myCache = manager.getCache("myCache");
            myCache.put(new Element("hoge", "HOGE"));

            myCache = manager.getCache("myCache");
            Element element = myCache.get("hoge");
            System.out.println("myCache.hoge = " + element.getObjectValue());
        } finally {
            manager.shutdown();
        }

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

ehcache.xml

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
    <cache name="myCache"
        maxEntriesLocalHeap="0">
    </cache>
</ehcache>

目录树 enter image description here

此问题之前已定义,但尚未解决。 java.lang.ExceptionInInitializerError when creating instance of EHCache in android

我会等待任何答案。

【问题讨论】:

    标签: java android ehcache


    【解决方案1】:

    我们需要 CacheException 的来源来告诉您发生了什么。但是,如果它不起作用,我不会感到惊讶。 Ehcache 2.x 不再维护。

    您可能想改用 Ehcache 3.x。如果它不起作用,我们将立即修复它。 :-)

    【讨论】:

      猜你喜欢
      • 2018-01-22
      • 2017-12-12
      • 2023-03-20
      • 2016-08-20
      • 2012-07-12
      • 2012-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多