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

  • Home
  • SEARCH
  • 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 6152669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:57:36+00:00 2026-05-23T19:57:36+00:00

Can anyone help me figure out why I’m getting a NullPointerException here? I’m trying

  • 0

Can anyone help me figure out why I’m getting a NullPointerException here?
I’m trying to set up an adapter for an ExpandableListViewActivity.

In the code below, I know my arrays are getting populated with objects, but when I attempt to retrieve the objects from the array in the adapter’s getGroupView() method, I get a nullpointerexception.

The funny thing is that I can get the name property of the object in the code line just before the error occurs.

public class Section extends ExpandableListActivity {

bpsection[] sectionsArray;
bpcategory[][] categoriesArray;
ExpandableListAdapter sectionsAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.act_section);



    LoadCategoriesTask loadingtask = new LoadCategoriesTask();
    loadingtask.execute();



}

private class bpsection {
    public int id;
    public String name;
    public int isadult;

    public bpsection(int _id, String _name, int _isadult) {
        this.id = _id;
        this.name = _name;
        this.isadult = _isadult;
    }

}

private class bpcategory extends bpsection {
    @SuppressWarnings("unused")
    public int section;

    public bpcategory(int _section, int _id, String _name, int _isadult) {
        super(_id, _name, _isadult);
        this.section = _section;
    }
}

/*
 * CUSTOM ADAPTER
 */

public class BPSectionsAdapter extends BaseExpandableListAdapter {

    private LayoutInflater blowMeUp;

    public BPSectionsAdapter(Context context)
    {
        blowMeUp = LayoutInflater.from(context);
    }

    @Override
    public Object getChild(int groupPosition, int childPosition) {
        return categoriesArray[groupPosition][childPosition];           
    }

    @Override
    public long getChildId(int groupPosition, int childPosition) {
        return categoriesArray[groupPosition][childPosition].id;
    }

    @Override
    public int getChildrenCount(int groupPosition) {
        return categoriesArray[groupPosition].length;
    }

    @Override
    public Object getGroup(int groupPosition) {
        return sectionsArray[groupPosition];
    }

    @Override
    public int getGroupCount() {
        return sectionsArray.length;
    }

    @Override
    public long getGroupId(int groupPosition) {
        return sectionsArray[groupPosition].id;
    }

    @Override
    public View getGroupView(int groupPosition, boolean isExpanded,
            View convertView, ViewGroup parent) {

        View parentView = blowMeUp.inflate(R.layout.itm_section, null);

        TextView tv = (TextView) parentView.findViewById(R.id.sectionView);

        Log.v("BPC", "Getting Group View for Section " + ((bpsection)getGroup(groupPosition)).name);
        if(tv == null)Log.v("BPC", "Text view isnull");
        if(((bpsection)getGroup(groupPosition)) == null)Log.v("BPC", "section is null");

        tv.setText(((bpsection)getGroup(groupPosition)).name);

        return parentView;
    }

    @Override
    public View getChildView(int groupPosition, int childPosition,
            boolean isLastChild, View convertView, ViewGroup parent) {
        View childView = convertView;
        if (childView == null) {
            childView = blowMeUp.inflate(R.layout.itm_category, null);
        }

        TextView tv = (TextView) childView.findViewById(R.id.categoryView);
        tv.setText(((bpcategory) getChild(groupPosition, childPosition)).name);

        return childView;

    }

    @Override
    public boolean hasStableIds() {
        return true;
    }

    @Override
    public boolean isChildSelectable(int groupPosition, int childPosition) {

        return false;
    }

}

/*
 * ASYNC TASK
 */

private class LoadCategoriesTask extends AsyncTask<Void, Void, Void> {

    private BPCDB db;

    @Override
    protected void onPostExecute(Void result) {
        sectionsAdapter = new BPSectionsAdapter(Section.this);
        setListAdapter(sectionsAdapter);
    }

    @Override
    protected Void doInBackground(Void... params) {

        ArrayList<bpcategory> categories;

        this.db = new BPCDB(getApplicationContext());

        db.open();
        Cursor c_section = db.getSections();
        if(c_section.getCount() > 1)
            try {
                db.dbhelper.copyDBFromAssets();
                c_section = db.getSections();
            } catch (IOException e) {

                e.printStackTrace();
            }
        sectionsArray = new bpsection[c_section.getCount()]; // We can init
                                                                // now that
                                                                // we have a
                                                                // count
        categoriesArray = new bpcategory[c_section.getCount()][];

        int i = 0;
        for (c_section.moveToFirst(); c_section.moveToNext(); c_section
                .isAfterLast()) {
            bpsection s = new bpsection(c_section.getInt(0), // id
                    c_section.getString(1), // name
                    c_section.getInt(2) // isadult
            );

            sectionsArray[i] = s;

            categories = new ArrayList<bpcategory>(); // Reinitialize
                                                        // category list for
                                                        // each section
                                                        // iteration
            Cursor c_category = db.getCategories(Integer.toString(s.id));

            // The first category of each section will be the "all whatever"
            // of the section
            categories.add(new bpcategory(s.id, 0, "all " + s.name,
                    s.isadult));

            for (c_category.moveToFirst(); c_category.moveToNext(); c_category
                    .isAfterLast()) {
                bpcategory c = new bpcategory(c_category.getInt(1),
                        c_category.getInt(0), c_category.getString(2),
                        c_category.getInt(3));

                categories.add(c);

            } // end of categories loop

            int size = categories.size();
            Log.v("BPC", "Section: " + s.name + "Categories: "+ size);
            categoriesArray[i] = categories.toArray(new bpcategory[size]);

        } // end of section loop
        Log.v("BPC", "Sections: " + sectionsArray.length);
        Log.v("BPC", "Categories: " + categoriesArray.length);
        return null;
    }

}

}

Here is the LogCat

07-13 06:27:57.719: VERBOSE/BPC(210): Getting Group View for Section services
07-13 06:27:57.719: VERBOSE/BPC(210): section is null
07-13 06:27:57.729: DEBUG/AndroidRuntime(210): Shutting down VM
07-13 06:27:57.729: WARN/dalvikvm(210): threadid=3: thread exiting with uncaught exception (group=0x4001aa28)
07-13 06:27:57.729: ERROR/AndroidRuntime(210): Uncaught handler: thread main exiting due to uncaught exception
07-13 06:27:57.749: ERROR/AndroidRuntime(210): java.lang.NullPointerException
07-13 06:27:57.749: ERROR/AndroidRuntime(210):     at com.mogulsoftware.android.bpcruiser.Section$BPSectionsAdapter.getGroupView(Section.java:117)
07-13 06:27:57.749: ERROR/AndroidRuntime(210):     at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:446)
07-13 06:27:57.749: ERROR/AndroidRuntime(210):     at android.widget.AbsListView.obtainView(AbsListView.java:1273)
07-13 06:27:57.749: ERROR/AndroidRuntime(210):     at android.widget.ListView.makeAndAddView(ListView.java:1658)
07-13 06:27:57.749: ERROR/AndroidRuntime(210):     at android.widget.ListView.fillDown(ListView.java:637)

The line that prompts the error (117) is:

tv.setText(((bpsection)getGroup(groupPosition)).name);

Any help is appreciated.

  • 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-05-23T19:57:36+00:00Added an answer on May 23, 2026 at 7:57 pm

    Please have a look at your loops when your are filling the section arrays. Looks like i does not get incremented. Maybe explain the statements in for(...) a litte more precisely

        int i = 0;
        for (c_section.moveToFirst(); c_section.moveToNext(); c_section
                .isAfterLast()) {
            bpsection s = new bpsection(c_section.getInt(0), // id
                    c_section.getString(1), // name
                    c_section.getInt(2) // isadult
            );
    
            sectionsArray[i] = s;
    
         ...
    
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone help me figure out how I could simplify this code, without using
I'm getting this error with this javascript can anyone help me figure out what
Can anyone help, i trying to figure what i need to do, i have
I am a beginner in mootools, can anyone help me figure out how to
Can anyone help me figure out how to use jmeter and force it to
Can anyone help me figure out how to search a URL and print a
Can anyone help me figure out why my background is not filling the entire
Can anyone help me figure out where I should be releasing exerciseArray ? I
Can anyone help me figure out a way to retreive the content of a
Can anyone help me with the trying to write SQL (MS SqlServer) - I

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.