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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T22:59:29+00:00 2026-06-08T22:59:29+00:00

In my Android application I’ve got an Activity containing an ExpandableListView . The items

  • 0

In my Android application I’ve got an Activity containing an ExpandableListView.

The items it will contain should be extracted from an XML file that the application will query to a Server when it starts (suppose the size of the file is not an issue).

The user should then be able to make modifications to the content of the XML file by adding, removing, editing items from the ExpandableListView with functionalities provided by the application. Eventually the application will send back the modified XML file to the Server.

For better understanding this mockup should explain what I’m trying to implement:

enter image description here

I’d like to know:

how can I populate dynamically in Java the area highlighted in red
given the XML file?

SAMPLE XML FILE:

<?xml version="1.0" encoding="utf-8"?>
<Category value="Animals">
    <entry>Cat</entry>
    <entry>Dog</entry>
    <entry>Elephant</entry>
</Category>
<Category value="Objects">
    <entry>Aeroplane</entry>
    <entry>Ball</entry>
    <entry>Closet</entry>
</Category>

ADDED DEBUG PART

I’ve tried to implement the solution proposed in the answer by @Luksprog but am facing a java.lang.NullPointerException when running the following code:

Code:

//gets the View from the Layout file
myCustomExpandableListView = (ExpandableListView) findViewById( R.id.myCustomExpandableListView );
//creates the array list that will contain all labels
ArrayList<Category> labelsInTaxonomy = new ArrayList<Category>();
//fills it with a private method that parses the XML and fills the array list
this.loadTaxonomyFromXml( labelsInTaxonomy );
//creates the custom expandable list adapter
CustomExpandable labelTaxonomyAdapter = new CustomExpandable( this, labelsInTaxonomy );
//sets the adapter
myCustomExpandableListView.setAdapter( labelTaxonomyAdapter );

Error:

E/AndroidRuntime( 5972): FATAL EXCEPTION: main
E/AndroidRuntime( 5972): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.DVA_HLUI/com.DVA_HLUI.DVA_HLUIManageTaxonomyActivity}: java.lang.NullPointerException
E/AndroidRuntime( 5972):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1816)
E/AndroidRuntime( 5972):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1837)
E/AndroidRuntime( 5972):    at android.app.ActivityThread.access$1500(ActivityThread.java:132)
E/AndroidRuntime( 5972):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1033)
E/AndroidRuntime( 5972):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 5972):    at android.os.Looper.loop(Looper.java:143)
E/AndroidRuntime( 5972):    at android.app.ActivityThread.main(ActivityThread.java:4196)
E/AndroidRuntime( 5972):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 5972):    at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 5972):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
E/AndroidRuntime( 5972):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
E/AndroidRuntime( 5972):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 5972): Caused by: java.lang.NullPointerException
E/AndroidRuntime( 5972):    at com.DVA_HLUI.DVA_HLUIManageTaxonomyActivity.onCreate(DVA_HLUIManageTaxonomyActivity.java:80)
E/AndroidRuntime( 5972):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1093)
E/AndroidRuntime( 5972):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1780)

Note that

com.DVA_HLUI.DVA_HLUIManageTaxonomyActivity.onCreate(DVA_HLUIManageTaxonomyActivity.java:80)

corresponds to this line of the code

myCustomExpandableListView.setAdapter( labelTaxonomyAdapter );

Any ideas of what I’m doing wrong?

  • 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-08T22:59:31+00:00Added an answer on June 8, 2026 at 10:59 pm

    I would make a custom class like this:

    class Category {
    
        private ArrayList<String> mEntries = new ArrayList<String>();
        private String mCaTegoryName;
    
        public void addEntry(String entry) {
            mEntries.add(entry);
        }
    
        public void setCategoryName(String categoryName) {
            mCaTegoryName = categoryName;
        }
    
        public ArrayList<String> getEntries() {
            return mEntries;
        }
    
        public String getCategoryName() {
            return mCaTegoryName;
        }
    }
    

    as a data structure and use the ArrayList<Category> that will result from parsing the xml in a custom adapter:

    class CustomExpandable extends BaseExpandableListAdapter {
    
        private ArrayList<Category> mItems;
    
        public CustomExpandable(Context context, ArrayList<Category> items) {
            mItems = items;
        }
    
        @Override
        public Object getChild(int groupPosition, int childPosition) {
            return mItems.get(groupPosition).getEntries().get(childPosition);
        }
    
        @Override
        public long getChildId(int groupPosition, int childPosition) {
            return 0;
        }
    
        @Override
        public View getChildView(int groupPosition, int childPosition,
                boolean isLastChild, View convertView, ViewGroup parent) {
            // implement the child view row
            return null;
        }
    
        @Override
        public int getChildrenCount(int groupPosition) {
            return mItems.get(groupPosition).getEntries().size();
        }
    
        @Override
        public Object getGroup(int groupPosition) {
            return mItems.get(groupPosition).getCategoryName();
        }
    
        @Override
        public int getGroupCount() {
            return mItems.size();
        }
    
        @Override
        public long getGroupId(int groupPosition) {
            return 0;
        }
    
        @Override
        public View getGroupView(int groupPosition, boolean isExpanded,
                View convertView, ViewGroup parent) {
            // implement the group View
            return null;
        }
    
        @Override
        public boolean hasStableIds() {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public boolean isChildSelectable(int groupPosition, int childPosition) {
            // TODO Auto-generated method stub
            return true;
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my Android application I need to parse xml like this: <items> <item title=@string/item1
In android application when second activity is being called from first one i want
An Android application has two activities. Activity A shows a list of items. Activity
My Android application connects to a service to request a file from our server.
Android application should show Events happening in city as per day/month/year anywhere in the
My android application takes sms messages from a BroadcastReceiver and copies the message into
My android application is saving some stats to internal storage. Each file name is
My android application sends a web service request and gets the response from web
In my Android application I get a response from a server in HTML format,
My android application need to print over wifi printer.Here wifi printer will be connected

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.