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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T12:00:58+00:00 2026-06-04T12:00:58+00:00

I am doing the dynamic ExpandableListView with a xml file, but I crashed when

  • 0

I am doing the dynamic ExpandableListView with a xml file, but I crashed when I load into the layout with no content in the list. Following is my code:

PasswordListingActivity.java:

public class PasswordListingActivity extends ExpandableListActivity {
    Button b_addPwd;
    ExpandableListView elv_pwdList;

    List<Map<String, String>> ServiceList = new ArrayList<Map<String, String>>();
    List<List<Map<String, String>>> DetailList = new ArrayList<List<Map<String, String>>>();

    ExpandableListAdapter adapter;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.passwordlisting);        

        b_addPwd = (Button)findViewById(R.id.b_addpwd);
        elv_pwdList = (ExpandableListView)findViewById(R.id.password_list);

        b_addPwd.setOnClickListener(new Button.OnClickListener(){
            @Override
            public void onClick(View arg0) {
                Intent intent = new Intent();
                intent.setClass(PasswordListingActivity.this, AddPasswordActivity.class);
                startActivityForResult(intent, 0);
            }           
    });

    adapter = new SimpleExpandableListAdapter(
            this, 
            ServiceList, 
            android.R.layout.simple_expandable_list_item_1, 
            new String[] {"SERVICE"}, 
            null, 
            DetailList, 
            android.R.layout.simple_expandable_list_item_2, 
            new String[] {"TITLE", "CONTENT",}, 
            null
    );
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data){
    switch (resultCode){
        case RESULT_OK:
            Bundle bundleR = data.getExtras();
            Map<String, String> ServiceGroupMap = new HashMap<String, String>();
            ServiceGroupMap.put("SERVICE", bundleR.getString("service"));
            ServiceList.add(ServiceGroupMap);
            List<Map<String, String>> DetailGroup = new ArrayList<Map<String, String>>();
            Map<String, String> DetailGroupMap = new HashMap<String, String>();
            DetailGroupMap.put("TITLE", "User Name: ");
            DetailGroupMap.put("CONTENT", bundleR.getString("username"));
            DetailGroup.add(DetailGroupMap);
            DetailGroupMap.put("TITLE", "Password: ");
            DetailGroupMap.put("CONTENT", bundleR.getString("password"));
            DetailGroup.add(DetailGroupMap);
            DetailList.add(DetailGroup);
            break;
        default:
            break;
    }
}

passwordlisting.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/white"
android:orientation="vertical" >
<TextView
    android:id="@+id/password_listing"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical|center_horizontal"
    android:text="@string/app_name"
    android:textColor="@color/black"
    android:textSize="20dip"
    android:textStyle="bold" />
<Button
    android:id="@+id/b_add_list"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/add" />
<ExpandableListView 
    android:id="@+id/password_list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />
</LinearLayout>

Error Code:

at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1615)

What is the problem of the code?

  • 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-04T12:00:59+00:00Added an answer on June 4, 2026 at 12:00 pm

    The ID of the button in your xml layout does not match the ID you are passing to findViewById();

    <Button
        android:id="@+id/b_add_list"
        ....
    

    and

    b_addPwd = (Button)findViewById(R.id.b_addpwd);
    

    the part after “R.id.” should match the part after “@+id/” What is happening is that you are getting null back from findViewById(); because there is no View found with the id R.id.b_addpwd. Then when you try to call .setOnClickListener() it is likely throwing a NullPointer exception.

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

Sidebar

Related Questions

I'm creating a website where I'm doing ajax requests to load some dynamic content
I'm doing some dynamic code generation using Reflection, and I've come across a situation
Hey all. I'm doing a linked list exercise that involves dynamic memory allocation, pointers,
Doing an ajax get request works as expected using the following code: $.ajax({ type:
Doing my first SL4 MVVM RIA based application and i ran into the following
I'm loading some python code from a database (it's doing dynamic mapping of values
I'm doing a style.php CSS file so I can use some dynamic variables in
I'm doing a Dynamic Actions on load for changing the image from a table
So in my JavaScript app I am doing some dynamic script injection etc during
I am used to doing dynamic Binding in PHP this way function ($className) {

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.