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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T03:04:53+00:00 2026-06-17T03:04:53+00:00

I want to open dialog on button click. My dialog is having listview which

  • 0

I want to open dialog on button click. My dialog is having listview which will display one image with text per row. But when i assign adapter to my listview it throws exception.

Here is my method to open dialog :

public void openShareDialog()

    {
        Dialog d = new Dialog(this);
        d.setTitle("Select Color Mode");
        d.setContentView(R.layout.share_list);

        String s[] = { "Facebook", "Twitter" };
        int image[] = { R.drawable.facebook, R.drawable.twitter };

        ArrayList<HashMap<String, String>> objArayList = new ArrayList<HashMap<String, String>>();

        for (int i = 0; i < 2; i++) {
            HashMap<String, String> listData = new HashMap<String, String>();
            listData.put("text", s[i]);
            listData.put("image", Integer.toString(image[i]));

            objArayList.add(listData);

        }

        String[] from = { "image", "text" };
        int[] to = { R.id.list_image, R.id.text };

        SimpleAdapter listAdapter = new SimpleAdapter(context, objArayList,
                R.layout.share_list_item, from, to);
        ListView lst1 = (ListView) findViewById(android.R.id.list);

        lst1.setAdapter(listAdapter);
        lst1.setOnItemClickListener(new OnItemClickListener() {

            public void onItemClick(AdapterView<?> parent, View view,
                    int position, long id) {

            }
        });

        d.show();

    }

my xml file :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:focusable="true"
    android:focusableInTouchMode="true"
    android:orientation="vertical" >

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:divider="#000000"
        android:dividerHeight="2dp" />

</RelativeLayout>

xml file for list row :

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

    <ImageView
        android:id="@+id/list_image"
        android:layout_width="50dip"
        android:layout_height="50dip"
        android:src="@drawable/listmusicicon" />

    <TextView
        android:id="@+id/text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/list_image"
        android:maxLines="1" />

</RelativeLayout>

When i set adapter it throws exception. So what is the problem ? Please suggest some solution.

The error is:

01-08 13:56:53.835: 
E/AndroidRuntime(734): 
FATAL EXCEPTION: main 01-08 13:56:53.835: 
E/AndroidRuntime(734): java.lang.NullPointerException 01-08 13:56:53.835: 
E/AndroidRuntime(734): at com.androidhive.musicplayer.AndroidBuildingMusicPlayerActivity.openShareDialog(A‌​ndroidBuildingMusicPlayerActivity.java:1346) 
01-08 13:56:53.835: E/AndroidRuntime(734): at com.androidhive.musicplayer.AndroidBuildingMusicPlayerActivity$15.onClick(Androi‌​dBuildingMusicPlayerActivity.java:481) 
01-08 13:56:53.835: 
E/AndroidRuntime(734): at android.view.View.performClick(View.java:4084)
  • 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-17T03:04:55+00:00Added an answer on June 17, 2026 at 3:04 am

    The error is here

    ListView lst1 = (ListView) findViewById(android.R.id.list);
    

    You are trying to access the list view from the main layout, not the dialog’s layout, you should try something like..

    ListView lst1 = (ListView) d.findViewById(android.R.id.list);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I saw this question, Show Open Dialog on a Button click : 'I have
I want open a Dialog with Controls and it must open if I click
I have a parent window from which i open a modal dialog on button
Using jQueryUI. When users click on the delete_comment_button image, I want a dialog to
I want the open dialog to filter files by *.spectrum or not filter it
I want to open a custom dialog in onHandleIntent() method of an IntentService class,
I want to show a open dialog for the user, where the user can
I want to open a MFC modeless dialog from a MFC dll injected into
I want to use the sharer.php popup to open the share dialog, but would
I want to resize the dialog dynamically just before I open it, but this

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.