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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:40:39+00:00 2026-05-31T15:40:39+00:00

I’m trying to view data from a database in an ExpandableListView (I’m first trying

  • 0

I’m trying to view data from a database in an ExpandableListView (I’m first trying to get it working with hard coded Strings).

I’ve used the following example: CodeWiki ExpandableListView

But I get a Runtime error when I click on a group to get the childView.

Categories1.java

public class CategoriesActivity1 extends Activity

{

ExpandableListView eListView;
ExpandableListAdapter eListAdapter;

ArrayList<String> groups;
ArrayList<ArrayList<ArrayList<String>>> children;

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.categories);

        eListView = (ExpandableListView)findViewById(R.id.expandableListView1);

        loadData();

        MyExpandableListAdapter adapter = new MyExpandableListAdapter(this, groups, children);

        eListView.setAdapter(adapter);


 }



 private void loadData(){

        groups= new ArrayList<String>();
        children= new ArrayList<ArrayList<ArrayList<String>>>();

        groups.add("Group 1");
        groups.add("Group 2");
        groups.add("Group 3");

        children.add(new ArrayList<ArrayList<String>>());
        children.get(0).add(new ArrayList<String>());
        children.get(0).get(0).add("Child 1 group 1");
        children.get(0).add(new ArrayList<String>());
        children.get(0).get(1).add("Child 2 group 1");
        children.get(0).add(new ArrayList<String>());
        children.get(0).get(2).add("Child 3 group 1");

        children.add(new ArrayList<ArrayList<String>>());
        children.get(1).add(new ArrayList<String>());
        children.get(1).get(0).add("Child 1 group 2");
        children.get(1).add(new ArrayList<String>());
        children.get(1).get(1).add("Child 2 group 2");
        children.get(1).add(new ArrayList<String>());
        children.get(1).get(2).add("Child 3 group 2");

        children.add(new ArrayList<ArrayList<String>>());
        children.get(2).add(new ArrayList<String>());
        children.get(2).get(0).add("Child 1 group 3");
        children.get(2).add(new ArrayList<String>());
        children.get(2).get(1).add("Child 2 group 3");
        children.get(2).add(new ArrayList<String>());
        children.get(2).get(2).add("Child 3 group 3");
    }

}

MyExpandableListAdapter.java

public class MyExpandableListAdapter extends BaseExpandableListAdapter

{

private ArrayList<String> groups;
    private ArrayList<ArrayList<ArrayList<String>>> children;
    private Context context;

public MyExpandableListAdapter(Context context, ArrayList<String> groups, ArrayList<ArrayList<ArrayList<String>>> children)
{
    this.context = context;
    this.groups = groups;
    this.children = children;
}

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

@Override
public ArrayList<String> getChild(int groupPosition, int childPosition)
{
    return children.get(groupPosition).get(childPosition);
}

@Override
public long getChildId(int groupPosition, int childPosition)
{
    return childPosition;
}

@Override
public View getChildView(int groupPosition, int childPosition,
        boolean isLastChild, View convertView, ViewGroup parent)
{
    String child = (String) ((ArrayList<String>)getChild(groupPosition, childPosition)).get(0);

    if(convertView == null)
    {
        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = layoutInflater.inflate(R.layout.categories_group, null);
    }

    TextView childTxt = (TextView)convertView.findViewById(R.id.TextViewChild01);

    childTxt.setText(child);

    return convertView;
}

@Override
public int getChildrenCount(int groupPosition)
{
    return children.get(groupPosition).size();
}

@Override
public Object getGroup(int groupPosition)
{
    return groups.get(groupPosition);
}

@Override
public int getGroupCount()
{
    return groups.size();
}

@Override
public long getGroupId(int groupPosition)
{
    return groupPosition;
}

@Override
public View getGroupView(int groupPosition, boolean isExpanded,
        View convertView, ViewGroup parent)
{
    String group = (String) getGroup(groupPosition);

    if(convertView == null)
    {
        LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = layoutInflater.inflate(R.layout.categories_group, null);
    }

    TextView groupTxt = (TextView) convertView.findViewById(R.id.TextViewGroup);

    groupTxt.setText(group);


    return convertView;
}

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

@Override
public boolean isChildSelectable(int groupPosition, int childPosition)
{
    return true;
}

}

categories_group.xml

     <?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/categoriesLLayout2"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/TextViewGroup" 
        android:layout_width="wrap_content"
        android:layout_height="50dp"
        android:layout_marginLeft="50dp"
        android:gravity="center_vertical"
    >
    </TextView>
    <TextView
        android:id="@+id/TextViewChild01" 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="30dp"
    >
    </TextView>
</LinearLayout>

Logcat:

03-17 15:16:13.468: E/AndroidRuntime(370): FATAL EXCEPTION: main
03-17 15:16:13.468: E/AndroidRuntime(370): java.lang.NullPointerException
03-17 15:16:13.468: E/AndroidRuntime(370): at nl.test.listing.activity.MyExpandableListAdapter.getChildView(MyExpandableListAdapter.java:64)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.widget.ExpandableListConnector.getView(ExpandableListConnector.java:450)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.widget.AbsListView.obtainView(AbsListView.java:1430)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.widget.ListView.measureHeightOfChildren(ListView.java:1216)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.widget.ListView.onMeasure(ListView.java:1127)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.view.View.measure(View.java:8313)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1017)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.widget.LinearLayout.measureVertical(LinearLayout.java:386)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.view.View.measure(View.java:8313)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.view.View.measure(View.java:8313)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.widget.LinearLayout.measureVertical(LinearLayout.java:531)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.widget.LinearLayout.onMeasure(LinearLayout.java:309)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.view.View.measure(View.java:8313)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:3138)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.widget.FrameLayout.onMeasure(FrameLayout.java:250)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.view.View.measure(View.java:8313)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.view.ViewRoot.performTraversals(ViewRoot.java:839)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.os.Handler.dispatchMessage(Handler.java:99)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.os.Looper.loop(Looper.java:123)
03-17 15:16:13.468: E/AndroidRuntime(370): at android.app.ActivityThread.main(ActivityThread.java:3683)
03-17 15:16:13.468: E/AndroidRuntime(370): at java.lang.reflect.Method.invokeNative(Native Method)
03-17 15:16:13.468: E/AndroidRuntime(370): at java.lang.reflect.Method.invoke(Method.java:507)
03-17 15:16:13.468: E/AndroidRuntime(370): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
03-17 15:16:13.468: E/AndroidRuntime(370): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
03-17 15:16:13.468: E/AndroidRuntime(370): at dalvik.system.NativeStart.main(Native Method)

I don’t know why I get this error, looking at the example I only changed the xml values from px to dp.

  • 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-31T15:40:40+00:00Added an answer on May 31, 2026 at 3:40 pm

    I think the problem is at class “MyExpandableListAdapter” at line number 64. Here it seems that there is some variable is becoming null at that moment. Can you paste the code at line number 64 in this class. SO that i can assist you more.

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

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from

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.