Banner-Slider icon indicating copy to clipboard operation
Banner-Slider copied to clipboard

problem in collapsing toolbarlayout

Open morteza-moradi opened this issue 7 years ago • 9 comments

when use this slider inside CollapsingToolbarLayout this error run:

Host activity must extend AppCompatActivity

java.lang.RuntimeException: **# Host activity must extend AppCompatActivity** at ss.com.bannerslider.views.BannerSlider$1.run(BannerSlider.java:117) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:135) at android.app.ActivityThread.main(ActivityThread.java:5254) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)

morteza-moradi avatar May 25 '17 18:05 morteza-moradi

Your activity that banner slider is on it, must extend AppCompatActivity

saeedsh92 avatar Jul 24 '17 10:07 saeedsh92

I have extended activity with AppCompatActivity still problem is not resolved

amitthorat avatar Jul 25 '17 09:07 amitthorat

Can you please upload the full code? I am working on a Design like that

Morteza-Rastgoo avatar Aug 15 '17 07:08 Morteza-Rastgoo

این مشکل منم هست . میشه راهنمایی کنین که چطور میتونم حلش کنم ؟

erik7667 avatar Aug 29 '17 07:08 erik7667

This library is Fragment based and it needed the Activity to use this. The problem is if you use the slider view into CollapsingToolbarLayout, so the result from the getContext() this library is ContextThemeWrapper instead AppCompatActivity.

You can solve the problem by obtaining the parent AppCompatActivity from that ContextThemeWrapper.

Open ss/com/bannerslider/views/BannerSlider.java file on line 121. And change it from:

if (getContext() instanceof AppCompatActivity) {
     hostActivity = (AppCompatActivity) getContext();
} else {
     throw new RuntimeException("Host activity must extend AppCompatActivity");
}

to

if (getContext() instanceof AppCompatActivity) {
    hostActivity = (AppCompatActivity) getContext();
} else if(getContext() instanceof android.view.ContextThemeWrapper){
    hostActivity = (AppCompatActivity) ((ContextWrapper) getContext()).getBaseContext(); // this is to get the AppCompatActivity from the ContextThemeWrapper
} else {
    throw new RuntimeException("Host activity must extend AppCompatActivity");
}

After that you can use the slider into CollapsingToolbarLayout view.

andisusilo avatar Oct 13 '17 08:10 andisusilo

@andisusilo tnx for your answer but could u tell me how change a jar file without open it ?

or how make it writable in android studio because files are read only .

ali-amani avatar Feb 07 '18 15:02 ali-amani

@ali-amani add this library as source, merge with your source code (download and merge with your source code). Don't adding in gradle.

andisusilo avatar Feb 07 '18 18:02 andisusilo

I have the same problem there is no better solution.

FahedHermoza avatar Oct 28 '18 02:10 FahedHermoza

when I using toolbar layout, interval was not working any solution ?

rizkidzulkarnain avatar Mar 05 '19 16:03 rizkidzulkarnain