Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash after clicking add view #2

Open
d-ramiz opened this issue Jun 21, 2015 · 4 comments
Open

Crash after clicking add view #2

d-ramiz opened this issue Jun 21, 2015 · 4 comments

Comments

@d-ramiz
Copy link

d-ramiz commented Jun 21, 2015

I was trying the demo in your library, and clicked the "Add View" button then scrolled to the right, the app crashed while scrolling, below is the exception

06-21 10:15:21.736 3328-3328/com.appl.carouselwidget E/AndroidRuntime﹕ FATAL EXCEPTION: main
Process: com.appl.carouselwidget, PID: 3328
java.lang.ClassCastException: com.appl.carouselwidget.MainActivity$MyFrame cannot be cast to com.appl.library.CoverFlowCarousel$CoverFrame
at com.appl.library.CoverFlowCarousel.getViewFromAdapter(CoverFlowCarousel.java:129)
at com.appl.library.Carousel.refillRightToLeft(Carousel.java:398)
at com.appl.library.Carousel.refill(Carousel.java:372)
at com.appl.library.Carousel.computeScroll(Carousel.java:179)
at com.appl.library.CoverFlowCarousel.computeScroll(CoverFlowCarousel.java:116)
at android.view.View.updateDisplayListIfDirty(View.java:14035)
at android.view.View.getDisplayList(View.java:14071)
at android.view.View.draw(View.java:14838)
at android.view.ViewGroup.drawChild(ViewGroup.java:3404)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3198)
at android.view.View.updateDisplayListIfDirty(View.java:14043)
at android.view.View.getDisplayList(View.java:14071)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3388)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3367)
at android.view.View.updateDisplayListIfDirty(View.java:14008)
at android.view.View.getDisplayList(View.java:14071)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3388)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3367)
at android.view.View.updateDisplayListIfDirty(View.java:14008)
at android.view.View.getDisplayList(View.java:14071)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3388)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3367)
at android.view.View.updateDisplayListIfDirty(View.java:14008)
at android.view.View.getDisplayList(View.java:14071)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3388)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3367)
at android.view.View.updateDisplayListIfDirty(View.java:14008)
at android.view.View.getDisplayList(View.java:14071)
at android.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:3388)
at android.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:3367)
at android.view.View.updateDisplayListIfDirty(View.java:14008)
at android.view.View.getDisplayList(View.java:14071)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:266)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:272)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:311)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2492)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2337)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1968)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1054)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:5779)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:767)
at android.view.Choreographer.doCallbacks(Choreographer.java:580)
at android.view.Choreographer.doFrame(Choreographer.java:550)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:753)
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:5221)
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:899)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

@GauravCreed
Copy link

is there any way to remove this error during scroll ,so please help me .

@byvlstr
Copy link

byvlstr commented Feb 17, 2016

I asked "applm", here is his reply :

View from adapter gets into viewcache without being wrapped int CoverFrame. Every view should be wrapped in coverFrame. I dont know how it can happen that one is not.
You can try debugging it. Or just add check with instanceof before cast and cast it only when correct class is supplied by cache.

I tried to put an "instanceof" before the cast, but the error still occurs. Don't get how this is possible...
Any ideas on how to fix this issue?

@gintechsystems
Copy link

I was able to fix this issue doing the following

protected View getViewFromAdapter(int position){
    CoverFrame finalFrame;
    View currView = mCache.getCachedView();
    if (currView instanceof CoverFrame) {
        finalFrame = (CoverFrame)currView;
        View recycled = finalFrame.getChildAt(0);

        View v = mAdapter.getView(position, recycled, this);

        finalFrame.setCover(v);
    }
    else {
        View v = mAdapter.getView(position, null, this);

        finalFrame = new CoverFrame(getContext(), v);
    }

    //to enable drawing cache
    if(android.os.Build.VERSION.SDK_INT >= 11) finalFrame.setLayerType(LAYER_TYPE_SOFTWARE, null);
    finalFrame.setDrawingCacheEnabled(true);

    return finalFrame;
}

@gintechsystems
Copy link

I will be forking this repo to improve upon it, thanks for the great library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants