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 8035467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:19:13+00:00 2026-06-05T02:19:13+00:00

Here is the getView method of my class DownloadableProjectsFromWebAdapter: @Override public View getView(int position,

  • 0

Here is the getView method of my class DownloadableProjectsFromWebAdapter:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View row = convertView;
    DownloadableProjectsFromWebHolder holder = null;

    if(row == null)
    {
        LayoutInflater inflater = ((Activity)context).getLayoutInflater();
        row = inflater.inflate(layoutResourceId, parent, false);

        holder = new DownloadableProjectsFromWebHolder();
        holder.txtPid = (TextView)row.findViewById(R.id.tvAllProjectsPid);
        holder.txtName = (TextView)row.findViewById(R.id.tvAllProjectsName);
        holder.txtShareable = (TextView)row.findViewById(R.id.tvAllProjectsShareable);

        row.setTag(holder);
    }
    else
    {
        holder = (DownloadableProjectsFromWebHolder)row.getTag();
    }

    String share_text;
    AllProjectListInfo li = data.get(position);
    holder.txtPid.setText("ID: " + Integer.toString(li.getId()));
    holder.txtName.setText(li.getName());
    if (li.getShareable()){
        share_text = "Public Project";
    } else {
        share_text = "Private Project";
    }
    holder.txtShareable.setText(share_text);

    return row;
}

The lines that are causing the issue:

35:    LayoutInflater inflater = ((Activity)context).getLayoutInflater();
36:    row = inflater.inflate(layoutResourceId, parent, false);

Here the info from LogCat:

FATAL EXCEPTION: main
java.lang.ClassCastException: android.app.ContextImpl cannot be cast to android.app.Activity
    at com.ericbrian.tnc.ConProForAndroid.DownloadableProjectsFromWebAdapter.getView(DownloadableProjectsFromWebAdapter.java:36)
    at android.widget.AbsListView.obtainView(AbsListView.java:2033)
    at android.widget.ListView.makeAndAddView(ListView.java:1772)
    at android.widget.ListView.fillDown(ListView.java:672)
    at android.widget.ListView.fillFromTop(ListView.java:732)
    at android.widget.ListView.layoutChildren(ListView.java:1625)
    at android.widget.AbsListView.onLayout(AbsListView.java:1863)
    at android.view.View.layout(View.java:11278)
    at android.view.ViewGroup.layout(ViewGroup.java:4224)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
    at android.view.View.layout(View.java:11278)
    at android.view.ViewGroup.layout(ViewGroup.java:4224)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
    at android.view.View.layout(View.java:11278)
    at android.view.ViewGroup.layout(ViewGroup.java:4224)
    at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1628)
    at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1486)
    at android.widget.LinearLayout.onLayout(LinearLayout.java:1399)
    at android.view.View.layout(View.java:11278)
    at android.view.ViewGroup.layout(ViewGroup.java:4224)
    at android.widget.FrameLayout.onLayout(FrameLayout.java:431)
    at android.view.View.layout(View.java:11278)
    at android.view.ViewGroup.layout(ViewGroup.java:4224)
    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1489)
    at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2442)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:137)
    at android.app.ActivityThread.main(ActivityThread.java:4424)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)

Here the calling the Adapter:

DownloadableProjectsFromWebAdapter adapter = 
    new DownloadableProjectsFromWebAdapter(
        getBaseContext(), 
        R.layout.all_projects_listview_item, 
        results);

And finally, the results definition:

List<AllProjectListInfo> results

Now, I copied this code from another place that where I use a custom adapter. However, that one works just fine. I don’t understand why this one doesn’t.

Any help is appreciated.

Thanks.

  • 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-05T02:19:15+00:00Added an answer on June 5, 2026 at 2:19 am

    Instead of this (which is mostly wrong):

    LayoutInflater inflater = ((Activity)context).getLayoutInflater();
    

    do this:

    LayoutInflater inflater = LayoutInflater.from(context);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's the view: @if (stream.StreamSourceId == 1) { <img class=source src=@Url.Content(~/Public/assets/images/own3dlogo.png) alt= /> }
I am working on a customized list view here is my adapter class public
In my ArrayAdapter class I capture the context passed in. Then int the getView
Here is my SQL script CREATE TABLE tracks( track_id int NOT NULL AUTO_INCREMENT, account_id
list_item.java public class List_Items extends ListActivity{ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.list_item); ListView
I have overrode the getView() method in ArrayAdapter . I was wondering if there
public class GalleryImageAdapter extends BaseAdapter{ private Activity activity; private ArrayList<String> listOfImages; public ImageLoader imageLoader;
I have an overriding Object class (Guide) with a subclass (Session). public class Guide
Why is my OnItemClickListener not working? public class UseAdp extends Activity { /** Called
I have a list view whose adapter is in a different class in a

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.