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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T10:23:50+00:00 2026-06-06T10:23:50+00:00

`Adapter class ::: public class YAdapter extends ArrayAdapter<String> { ArrayList<String> items; Context context; private

  • 0
    `Adapter class :::


    public class YAdapter extends ArrayAdapter<String> {

        ArrayList<String> items;
        Context context;
        private LayoutInflater mInflater;

        static class ViewHolder {
            TextView yName;
        }

        public YAdapter(Context context,ArrayList<String> items) {
            super(context, R.layout.single_item_list_row, items);
            this.context=context;
            mInflater = LayoutInflater.from(context);
            this.items = items;
        }

        @Override
        public int getCount() {
            return items.size();
        }

        @Override
        public String getItem(int arg0) {
            return items.get(arg0);
        }

        @Override
        public long getItemId(int arg0) {
            return arg0;
        }





    @Override
public View getView(final int position, View convertView, ViewGroup parent) {
    final ViewHolder holder;

    if(convertView == null) {
        convertView = Inflater.inflate(R.layout.single_item_list_row,null);
        holder = new ViewHolder();
        holder.yName=(TextView)convertView.findViewById(R.id.text1);
        convertView.setTag(holder);
           } 
                else {
                    holder = (ViewHolder) convertView.getTag();
                }
                try
                {
                    if(items.get(position) != null)
                        holder.yName.setText(items.get(position));  
                }
                catch (Exception e) {
                      Log.e("ERROR","Adapter error in generating view);
                }
                return convertView;
            }

        }

        Activity Class ::



        public class DemoActivity extends Activity {


            ListView listView;
            ArrayList<String> temp = new ArrayList<String>();
            YAdapter adapter;

            @Override
            public void onCreate(Bundle savedInstanceState) {
                super.onCreate(savedInstanceState);
                setContentView(R.layout.main);
    listView = (ListView) findViewById(R.id.list);


            }
                @Override
            public void onResume() {
                super.onResume();
                temp.add("one");
                temp.add("two");
                temp.add("three");
                temp.add("four");
                adapter = new YAdapter(DemoActivity.this , temp);


                **listView.setAdapter(adapter);**  -- exception

            }
            }

    listView.setAdapter(adapter);

this line causes an exception.

when i try setting adapter to list it gives error if i remove this line no error is displayed and also no components on screen are displayed only a black screen appears.

What i have coded is shown below bt i am getting null pointer exception .Please tell me what i have missed ?

  • 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-06T10:23:51+00:00Added an answer on June 6, 2026 at 10:23 am

    as using @ViewById(R.id.list) so no need to findViewById…..

    issue is due

    adapter = new YAdapter(YellowPagesActivity.this , temp);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I 've the following custom adapter public class GroupAdapter extends ArrayAdapter<Group> { private ArrayList<Group>
I created an adapter public class MyArrayAdapter extends ArrayAdapter<Watch> overriding public MyArrayAdapter(Context context, List<Watch>
public class DataViewActivity extends Activity{ SQLiteDatabase db; SimpleCursorAdapter adapter; String dbTable = users; @Override
There is a list adapter: public class timetable_list_adapter extends BaseAdapter { ... } and
hi I am trying to get my arraylist value into my image adapter class
My code as follows: public class wall extends Activity { GridView webgridview; Button web;
My Custom Adapter that extends SimpleCursorAdapter for my ListFragment does not display the items
I have made a custom adapter class here is the code public class CustomArrayAdapterForReceipts
I am using a CursorAdapter to handle my ListActivity : public class Mclass extends
I am working on a customized list view here is my adapter class public

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.