gotokatsuya / KenBurnsView

Slideshow. Android ImageViews are animated by Ken Burns Effect. (Inspired by Heyday)
Apache License 2.0
213 stars 38 forks source link

Crash when no images are set #7

Open fdonzello opened 8 years ago

fdonzello commented 8 years ago

Hi,

as in subject..

I have to remove from the layout to avoid the crash..

fasteque commented 8 years ago

I'm facing the same issue

08-17 15:17:38.134 6189-6189/com.swisscom.mycloud E/AndroidRuntime: FATAL EXCEPTION: main
                                                                    Process: com.swisscom.mycloud, PID: 6189
                                                                    java.lang.NullPointerException: Attempt to get length of null array
                                                                        at com.goka.kenburnsview.KenBurnsView.autoSwapImage(KenBurnsView.java:181)
                                                                        at com.goka.kenburnsview.KenBurnsView.access$000(KenBurnsView.java:22)
                                                                        at com.goka.kenburnsview.KenBurnsView$1.run(KenBurnsView.java:274)
                                                                        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)

I think the issue is the animation is started when onAttachedToWindow is called, but if you have the view set in the layout it can crash as soon as you start the Activity.

alaaghribi commented 7 years ago

I have the same problem, and the dev did not respond since March ...

fasteque commented 7 years ago

@alaaghribi you can always fork it or push a fix or take this as an inspiration and do your own implementation. I think this library works pretty well, so I wouldn't drop it ;)

sashafiero commented 7 years ago

I had this crop up, and what fixed it for me was realizing that I'd put the view_pager_frame FrameLayout INSIDE the KenBurnsView. Once I realized it was supposed to be on top of it (so to speak), and moved it to outside the KenBurnsView, it worked.

tomeroto commented 7 years ago

can you give sample layout? I have same problem :(

sashafiero commented 7 years ago
<RelativeLayout>
    <com.goka.kenburnsview.KenBurnsView
        android:id="@+id/tablet_sidebar"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_toLeftOf="@id/tablet_content"/>

    <FrameLayout
        android:id="@+id/view_pager_frame"
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"/>
</RelativeLayout>

They are sibling elements, not parent/child, which was my first problem.