致命异常:com.squareup.okhttp.Cache中的主要java.lang.ExceptionInInitializerError。<init>(Cache.java:172)

时间:2017-11-11 16:41:30

标签: java android runtime-error okhttp

我正在使用&#34;编译&#39; com.daimajia.slider:library:1.1.5@aar'&#34;通过将图像的URL传递给它来显示图像的库会引发错误。

ArrayList varible包含多图像的URL。

https://www.android-examples.com/android-multiple-auto-image-slider-example-tutorial-using-online-url/

app.gradle

 defaultConfig {
        applicationId "com.google.tho.oe"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
        multiDexEnabled true
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }

compile 'com.squareup.okhttp:okhttp:2.5.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.github.bumptech.glide:glide:3.8.0'
compile 'com.nineoldandroids:library:2.4.0'
compile 'com.daimajia.slider:library:1.1.5@aar'

班级的一些主要内容

private ArrayList<String> collecter = new ArrayList<>();
sliderLayout = (SliderLayout)findViewById(R.id.slider);

TextSliderView textSliderView = new TextSliderView(Main2Activity.this);
        for (int i = 0; i<collecter.size();i++ ) {

            textSliderView
                    .description(collecter.get(i))
                    .image(collecter.get(i).toString())
                    .setScaleType(BaseSliderView.ScaleType.Fit)
                    .setOnSliderClickListener(Main2Activity.this);
            textSliderView.bundle(new Bundle());
            textSliderView.getBundle()
                    .putString("extra", collecter.get(i));
            Toast.makeText(getApplicationContext(),"HI Thofiq"+collecter.get(i),Toast.LENGTH_LONG).show();

        }
        sliderLayout.addSlider(textSliderView);
        sliderLayout.setPresetTransformer(SliderLayout.Transformer.Accordion);
        sliderLayout.setPresetIndicator(SliderLayout.PresetIndicators.Center_Bottom);
        sliderLayout.setCustomAnimation(new DescriptionAnimation());
        sliderLayout.setDuration(3000);
        sliderLayout.addOnPageChangeListener(this);

错误:

   11-11 21:25:30.045 18458-18458/com.google.tho.oe E/AndroidRuntime: FATAL EXCEPTION: main
                                                                       java.lang.ExceptionInInitializerError
                                                                           at com.squareup.okhttp.Cache.<init>(Cache.java:172)
                                                                           at com.squareup.okhttp.Cache.<init>(Cache.java:168)
                                                                           at com.squareup.picasso.OkHttpDownloader.<init>(OkHttpDownloader.java:78)
                                                                           at com.squareup.picasso.OkHttpDownloader.<init>(OkHttpDownloader.java:55)
                                                                           at com.squareup.picasso.OkHttpDownloader.<init>(OkHttpDownloader.java:45)
                                                                           at com.squareup.picasso.Utils$OkHttpLoaderCreator.create(Utils.java:424)
                                                                           at com.squareup.picasso.Utils.createDefaultDownloader(Utils.java:250)
                                                                           at com.squareup.picasso.Picasso$Builder.build(Picasso.java:832)
                                                                           at com.squareup.picasso.Picasso.with(Picasso.java:662)
                                                                           at com.daimajia.slider.library.SliderTypes.BaseSliderView.bindEventAndShow(BaseSliderView.java:210)
                                                                           at com.daimajia.slider.library.SliderTypes.TextSliderView.getView(TextSliderView.java:25)
                                                                           at com.daimajia.slider.library.SliderAdapter.instantiateItem(SliderAdapter.java:81)
                                                                           at com.daimajia.slider.library.Tricks.InfinitePagerAdapter.instantiateItem(InfinitePagerAdapter.java:54)
                                                                           at com.daimajia.slider.library.Tricks.ViewPagerEx.addNewItem(ViewPagerEx.java:848)
                                                                           at com.daimajia.slider.library.Tricks.ViewPagerEx.populate(ViewPagerEx.java:998)
                                                                           at com.daimajia.slider.library.Tricks.ViewPagerEx.populate(ViewPagerEx.java:930)
                                                                           at com.daimajia.slider.library.Tricks.ViewPagerEx.onMeasure(ViewPagerEx.java:1453)
                                                                           at android.view.View.measure(View.java:15371)
                                                                           at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
                                                                           at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
                                                                           at android.view.View.measure(View.java:15371)
                                                                           at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
                                                                           at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
                                                                           at android.view.View.measure(View.java:15371)
                                                                           at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:617)
                                                                           at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:399)
                                                                           at android.view.View.measure(View.java:15371)
                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4876)
                                                                           at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
                                                                           at android.support.v7.widget.ContentFrameLayout.onMeasure(ContentFrameLayout.java:139)
                                                                           at android.view.View.measure(View.java:15371)
                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4876)
                                                                           at android.support.v7.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:393)
                                                                           at android.view.View.measure(View.java:15371)
                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4876)
                                                                           at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
                                                                           at android.view.View.measure(View.java:15371)
                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4876)
                                                                           at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1396)
                                                                           at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
                                                                           at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
                                                                           at android.view.View.measure(View.java:15371)
                                                                           at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4876)
                                                                           at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
                                                                           at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2423)
                                                                           at android.view.View.measure(View.java:15371)
                                                                           at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2011)
                                                                           at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1250)
                                                                           at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1425)
                                                                           at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1143)
                                                                           at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4674)
                                                                           at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
                                                                           at android.view.Choreographer.doCallbacks(Choreographer.java:555)
                                                                           at android.view.Choreographer.doFrame(Choreographer.java:525)
                                                                           at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
                                                                           at android.os.Handler.handleCallback(Handler.java:615)
                                                                           at android.os.Handler.dispatchMessage(Handler.java:92)
                                                                        at android.os

1 个答案:

答案 0 :(得分:0)

尝试删除mandatory number 0此依赖项。如果您的图像加载器库使用不同版本的okhttp,这可能会导致错误。您必须添加下一个依赖项

compile 'com.squareup.okhttp:okhttp:2.5.0'

}

并使用示例中的库版本,因为可能与新版本不兼容。 并查看您是否忘记在清单中添加权限

dependencies {
    compile "com.android.support:support-v4:+"
    compile 'com.squareup.picasso:picasso:2.3.2'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.daimajia.slider:library:1.1.5@aar'

如果您有2个或更多<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> ... 个实例,也会发生错误。所以检查一下。 并且由IntelliJ Amiya撰写,你可以在githab上看到这个问题https://github.com/square/okhttp/issues/2228 也许那里给出的解决方案对你有帮助,但它适用于okhttp所以你应该更改daimajia.slider lib中的代码。