Frank-Zhu / PullZoomView

An Android custom ListView and ScrollView with pull to zoom-in.
Apache License 2.0
2.32k stars 624 forks source link

getSerializableExtra Error #12

Closed Sorush-moradisani closed 9 years ago

Sorush-moradisani commented 9 years ago

Hi. I'm trying to set my contents from java class but it gives me the following error: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.samanefarhangi/com.example.samanefarhangi.PullToZoomScrollActivity}: java.lang.ClassCastException: com.example.samanefarhangi.pulllib.PullToZoomScrollViewEx cannot be cast to com.example.samanefarhangi.pulllib.PullToZoomScrollView at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2439) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2495) at android.app.ActivityThread.access$800(ActivityThread.java:153) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1349) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:157) at android.app.ActivityThread.main(ActivityThread.java:5633) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:896) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:712) at dalvik.system.NativeStart.main(Native Method) Caused by: java.lang.ClassCastException: com.example.samanefarhangi.pulllib.PullToZoomScrollViewEx cannot be cast to com.example.samanefarhangi.pulllib.PullToZoomScrollView

here is the code: private void loadViewForCode() {

    feed = (FeedItem) this.getIntent().getSerializableExtra("feed");
    PullToZoomScrollView scrollView = (PullToZoomScrollView) findViewById(R.id.scroll_view);
    View headView = LayoutInflater.from(this).inflate(R.layout.profile_head_view, null, false);

    TextView title = (TextView) headView.findViewById(R.id.tv_title);
    title.setText(feed.getTitle());

    TextView author = (TextView) headView.findViewById(R.id.tv_author);
    author.setText(feed.getAuthor());

    TextView date = (TextView) headView.findViewById(R.id.tv_date);
    date.setText(feed.getDate());

    View zoomView = LayoutInflater.from(this).inflate(R.layout.profile_zoom_view, null, false);

    ImageView contentImage = (ImageView) headView.findViewById(R.id.iv_user_head);
    try {
        new ImageDownloaderTask(contentImage).execute(feed.getAttachmentUrl());
    }catch (Exception e){
        e.printStackTrace();
    }

    View contentView = LayoutInflater.from(this).inflate(R.layout.profile_content_view, null, false);

    TextView htmlTextView = (TextView) contentView.findViewById(R.id.tv_content);
    htmlTextView.setText(Html.fromHtml(feed.getContent(), null, null));

    scrollView.setHeaderContainer(headView);
    scrollView.setZoomView(zoomView);
    scrollView.setContentContainerView(contentView);
}

I think it's a library problem!

Frank-Zhu commented 9 years ago

@Sorush-moradisani Caused by: java.lang.ClassCastException: com.example.samanefarhangi.pulllib.PullToZoomScrollViewEx cannot be cast to com.example.samanefarhangi.pulllib.PullToZoomScrollView

PullToZoomScrollView scrollView = (PullToZoomScrollView) findViewById(R.id.scroll_view); --> change to PullToZoomScrollViewEx scrollView = (PullToZoomScrollViewEx) findViewById(R.id.scroll_view); and try it.

Frank-Zhu commented 9 years ago

@Sorush-moradisani I update this code,you update and try it.

Sorush-moradisani commented 9 years ago

I changed it but it gives another error! Here is it: prob it doesn't resolve setHeaderContainer and setContentContainerView!

Sorush-moradisani commented 9 years ago

Problem solved! I don't need setHeaderContainer and setContentContainerView!

    private void loadViewForCode() {
        PullToZoomScrollViewEx scrollView = (PullToZoomScrollViewEx) findViewById(R.id.scroll_view);
        View headView = LayoutInflater.from(this).inflate(R.layout.profile_head_view, null, false);

    TextView title = (TextView) findViewById(R.id.tv_title);
    title.setText(feed.getTitle());

    TextView author = (TextView) findViewById(R.id.tv_author);
    author.setText(feed.getAuthor());

    TextView date = (TextView) findViewById(R.id.tv_date);
    date.setText(feed.getDate());

    View zoomView = LayoutInflater.from(this).inflate(R.layout.profile_zoom_view, null, false);

    ImageView contentImage = (ImageView) findViewById(R.id.iv_zoom);
    try {
        new ImageDownloaderTask(contentImage).execute(feed.getAttachmentUrl());
    }catch (Exception e){
        e.printStackTrace();
    }

    View contentView = LayoutInflater.from(this).inflate(R.layout.profile_content_view, null, false);

    TextView htmlTextView = (TextView) findViewById(R.id.tv_content);
    htmlTextView.setText(Html.fromHtml(feed.getContent(), null, null));

    //scrollView.setHeaderContainer(headView);
    scrollView.setZoomView(zoomView);
    //scrollView.setContentContainerView(contentView);
}
Frank-Zhu commented 9 years ago

@Sorush-moradisani you can try this

private void loadViewForCode() {
        PullToZoomScrollViewEx scrollView = (PullToZoomScrollViewEx) findViewById(R.id.scroll_view);
        View headView = LayoutInflater.from(this).inflate(R.layout.profile_head_view, null, false);
        View zoomView = LayoutInflater.from(this).inflate(R.layout.profile_zoom_view, null, false);
        View contentView = LayoutInflater.from(this).inflate(R.layout.profile_content_view, null, false);
        scrollView.setHeaderView(headView);
        scrollView.setZoomView(zoomView);
        scrollView.setScrollContentView(contentView);
    }
Sorush-moradisani commented 9 years ago

Tnx! It works pretty fine!