Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8710753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:42:19+00:00 2026-06-13T04:42:19+00:00

I am trying to return 2 different type of views in the BaseAdapter’s getView

  • 0

I am trying to return 2 different type of views in the BaseAdapter’s getView method according to the position .

But I am getting ClassCastException. Below is my code:

public View getView(final int position, View convertView, ViewGroup parent) {
    if(position != 5){

        WebPageView web;
        if(convertView == null){

            web = new WebPageView(mContext, new Point(parent.getWidth(), parent.getHeight()), parent);

    } else {
        web = (WebPageView) convertView;

    }

        web.setPage("http://yahoo.com");
        return web;
    }else{
    final PageView pageView;
    if (convertView == null) {
        pageView = new PageView(mContext);
    } else {
        pageView = (PageView) convertView;
    }


    return pageView;
}
}

But I am getting always ClassCastException. When I am using WebPageView or PageView alone in getView, I am not getting the exception.

Anyone having any idea?

Below is my logcat output.

10-18 18:03:59.250: E/AndroidRuntime(31390): FATAL EXCEPTION: main
10-18 18:03:59.250: E/AndroidRuntime(31390): java.lang.ClassCastException: com.getit.WebPageView cannot be cast to com.getit.PageView
10-18 18:03:59.250: E/AndroidRuntime(31390):    at com.getit.PageAdapter.getView(PageAdapter.java:94)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at com.getit.CustomGalleryView.getOrCreateChild(CustomGalleryView.java:467)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at com.getit.CustomGalleryView.onLayout(CustomGalleryView.java:422)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.view.View.layout(View.java:13754)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.view.ViewGroup.layout(ViewGroup.java:4364)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.widget.RelativeLayout.onLayout(RelativeLayout.java:948)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.view.View.layout(View.java:13754)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.view.ViewGroup.layout(ViewGroup.java:4364)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.view.View.layout(View.java:13754)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.view.ViewGroup.layout(ViewGroup.java:4364)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1649)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1507)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.widget.LinearLayout.onLayout(LinearLayout.java:1420)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.view.View.layout(View.java:13754)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.view.ViewGroup.layout(ViewGroup.java:4364)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.view.View.layout(View.java:13754)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.view.ViewGroup.layout(ViewGroup.java:4364)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1868)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1689)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1000)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4214)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.view.Choreographer.doCallbacks(Choreographer.java:555)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.view.Choreographer.doFrame(Choreographer.java:525)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.os.Handler.handleCallback(Handler.java:615)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.os.Handler.dispatchMessage(Handler.java:92)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.os.Looper.loop(Looper.java:137)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at android.app.ActivityThread.main(ActivityThread.java:4745)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at java.lang.reflect.Method.invokeNative(Native Method)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at java.lang.reflect.Method.invoke(Method.java:511)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-18 18:03:59.250: E/AndroidRuntime(31390):    at dalvik.system.NativeStart.main(Native Method)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:42:20+00:00Added an answer on June 13, 2026 at 4:42 am

    You get this error because you try to recycle a view that was already cast to another object.I don’t know if you use custom objects or not as if both were extending a common class it would have worked.You can do 2 things:

    1:Check if convertview is an istance of your custom object.This ensures that you not try to cast pageview to a webview or viceversa

    if (convertView == null || !convertView instanceof PageView) {
        pageView = new PageView(mContext);
    } else {
        pageView = (PageView) convertView;
    }
    

    same check for webview aswell.

    2:Instantiate every time a new object

    if(position != 5){
    WebPageView web;
    web = new WebPageView(mContext, new Point(parent.getWidth(), parent.getHeight()), parent);
    web.setPage("http://yahoo.com");
    return web;
    }else{
    final PageView pageView;
    pageView = new PageView(mContext);
    return pageView;
    }
    

    not really advised but still…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to return the value by using unix_timestamp function but it behaves
I am trying to update the UITableViewCell view with a different type of theme.
I have done this previously but in a different way. I am trying to
I have a method that I call multiple times, but each time a different
Im trying to return the value that a $ajax call returns, from a function
Im trying to return a SimpleQuery list that queries a single table and uses
Am trying to return the sum of each day of a week in mysql
I'm trying to return the most common elements in a list (statistical mode). Unfortunately
I'm trying to return a left child as a pointer I have template <typename
I am trying to return two json sets from java which each contain key/value

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.