sayyam / carouselview

A simple library to add carousel view in android app.
Apache License 2.0
1.15k stars 260 forks source link

cannot add CarouselView dinamically #92

Open dmaglio opened 6 years ago

dmaglio commented 6 years ago

If i try to add dinamically CarouselView in my activity i have this error

E/AndroidRuntime: FATAL EXCEPTION: main
                  Process: org.rina.andiamoapp, PID: 18659
                  java.lang.RuntimeException: Unable to start activity ComponentInfo : java.lang.NullPointerException: Attempt to invoke virtual method 'void com.synnapps.carouselview.CarouselViewPager.setAdapter(android.support.v4.view.PagerAdapter)' on a null object reference
                      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2794)
                      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2878)
                      at android.app.ActivityThread.-wrap11(Unknown Source:0)
                      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1605)
                      at android.os.Handler.dispatchMessage(Handler.java:106)
                      at android.os.Looper.loop(Looper.java:164)
                      at android.app.ActivityThread.main(ActivityThread.java:6520)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:442)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
                   Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void com.synnapps.carouselview.CarouselViewPager.setAdapter(android.support.v4.view.PagerAdapter)' on a null object reference
                      at com.synnapps.carouselview.CarouselView.setData(CarouselView.java:244)
                      at com.synnapps.carouselview.CarouselView.setPageCount(CarouselView.java:431)
                      ...
Fmijsters commented 6 years ago

This ^^

danielFarre commented 5 years ago

The default is not correct, you need to pass second parameter as null

new CarouselView(getActivity(), null);

because the default constructor don't inizialise the adapter.