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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T18:52:49+00:00 2026-06-15T18:52:49+00:00

I have a dialog in Android, as a layout I use this file: <?xml

  • 0

I have a dialog in Android, as a layout I use this file:

<?xml version="1.0" encoding="utf-8"?> <ListView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >


</ListView>

In the Activity I need to add a Adapter to this ListView, I have this:

@Override
protected Dialog onCreateDialog(int id) {
    switch(id){
    case ADDPLAYERDIALOG:{
        Dialog d = new Dialog(this);            
        d.setContentView(R.layout.training_dialog);
        ListView lv = (ListView) d.getCurrentFocus().getRootView(); 
        ListAdapter adapter = new ArrayAdapter<String>(getBaseContext(), android.R.layout.simple_list_item_1, createNamesList());   
        lv.setAdapter(adapter);     

    return d;
    }
    }
    return super.onCreateDialog(id);
}

I get a NullPointerException here:

 ListView lv = (ListView) d.getCurrentFocus().getRootView();

I don’t have the id for this ListView widget, because it is a layout XML-file, and I can’t just write lv = d.findViewById(R.id.listview);

How can I solve the problem?

  • 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-15T18:52:50+00:00Added an answer on June 15, 2026 at 6:52 pm

    You can easily set an id through xml. You use the android:id tag.

    Your listview node should look something like this:

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

    Now your lv = d.findViewById(R.id.listview); should work.

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

Sidebar

Related Questions

I have a faux dialog which uses this layout: <?xml version=1.0 encoding=utf-8?> <FrameLayout xmlns:android=http://schemas.android.com/apk/res/android
I have a class that extends android.app.Dialog, the layout is done in an xml
I have a dialog with this content: <RelativeLayout android:layout_width=wrap_content android:layout_height=wrap_content > <ScrollView android:layout_width=fill_parent android:layout_height=wrap_content
I am designing custom dialogue in android, For this purpose I designed xml file
I have been attempting to use an android.preference.DialogPreference inflated from XML, but the documentation
I want to use Android pdf library http://andpdf.sourceforge.net/ , but i have same error.
I have the below xml code which i use to display inside a Dialog.
I have one main Activity with layout wrapped into ScrollView like this: <ScrollView android:layout_height=wrap_content
I have a dialog with a custom theme: final Dialog d = new Dialog(this,android.R.style.Theme_Translucent_NoTitleBar_Fullscreen);
I use Spinner in Dialog Mode. I set SimpleCursorAdapter for the Spinner with setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

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.