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

  • Home
  • SEARCH
  • 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 8359997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:19:33+00:00 2026-06-09T11:19:33+00:00

I have a DialogFragment that creates a listview dialog and on a list item

  • 0

I have a DialogFragment that creates a listview dialog and on a list item click I want to display an alert dialog but when I create the dialog it gives me a NullPointerException with an error that I have never seen before

08-05 11:40:42.315: E/AndroidRuntime(4693): java.lang.NullPointerException
08-05 11:40:42.315: E/AndroidRuntime(4693):     at android.app.AlertDialog.resolveDialogTheme(AlertDialog.java:142)
08-05 11:40:42.315: E/AndroidRuntime(4693):     at android.app.AlertDialog$Builder.<init>(AlertDialog.java:359)
08-05 11:40:42.315: E/AndroidRuntime(4693):     at com.tyczj.bowling.dialogs.SeasonType$1$1.onClick(SeasonType.java:60)
08-05 11:40:42.315: E/AndroidRuntime(4693):     at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
08-05 11:40:42.315: E/AndroidRuntime(4693):     at android.os.Handler.dispatchMessage(Handler.java:99)
08-05 11:40:42.315: E/AndroidRuntime(4693):     at android.os.Looper.loop(Looper.java:137)
08-05 11:40:42.315: E/AndroidRuntime(4693):     at android.app.ActivityThread.main(ActivityThread.java:4745)
08-05 11:40:42.315: E/AndroidRuntime(4693):     at java.lang.reflect.Method.invokeNative(Native Method)
08-05 11:40:42.315: E/AndroidRuntime(4693):     at java.lang.reflect.Method.invoke(Method.java:511)
08-05 11:40:42.315: E/AndroidRuntime(4693):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
08-05 11:40:42.315: E/AndroidRuntime(4693):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
08-05 11:40:42.315: E/AndroidRuntime(4693):     at dalvik.system.NativeStart.main(Native Method)

Here is my Dialog’s onCreate

@Override
public Dialog onCreateDialog(Bundle state){
    final Dialog d = new Dialog(getActivity());
    d.setContentView(R.layout.dialog_layout);
    d.setTitle("Select a season");
    ListView lv = (ListView)d.findViewById(R.id.dialog_list);
    String[] list = getResources().getStringArray(R.array.season_dialog_type);
    lv.setAdapter(new ArrayAdapter<String>(getActivity(),R.layout.stats_list_layout,list));
    lv.setOnItemClickListener(new OnItemClickListener(){

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
            d.dismiss();
            FragmentTransaction ft = getFragmentManager().beginTransaction();
            if(arg2 == 0){
                DialogFragment df = new SeasonsDialog(true);
                df.show(ft,null);
            }else if(arg2 == 1){
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                final View v = getActivity().getLayoutInflater().inflate(R.layout.add_season_layout, null, false);
                builder.setTitle("Add a season").setView(v).setPositiveButton("Add", new OnClickListener(){

                    @Override
                    public void onClick(DialogInterface arg0, int arg1) {
                        arg0.dismiss();
                        AlertDialog.Builder builder2 = new AlertDialog.Builder(getActivity()); //Error here
                        builder2.setTitle("Warning!").setMessage("Adding a new season will cause all new games to be under this season.\n\n Do you wish to continue?")
                        .setPositiveButton("Yes", new OnClickListener(){

                            @Override
                            public void onClick(DialogInterface dialog,int which) {
                                dialog.dismiss();
                                EditText et = (EditText)v.findViewById(R.id.editText1);
                                ContentValues values = new ContentValues();
                                values.put(Games.SEASON, et.getText().toString());
                                Uri uri = getActivity().getContentResolver().insert(Games.SEASONS_URI, values);
                                et.setText("");
                                SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getActivity());
                                SharedPreferences.Editor edit = pref.edit();
                                edit.putLong(Preferences.SELECTED_SEASON, ContentUris.parseId(uri)).commit();
                            }

                        }).setNegativeButton("No", new OnClickListener(){

                            @Override
                            public void onClick(DialogInterface dialog,int which) {
                                dialog.dismiss();
                            }

                        }).create().show();
                    }

                }).setNegativeButton("Cancel", new OnClickListener(){

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }

                }).create().show();
            }

        }

    });

    return d;
}

it error’s out at this line in my onClick

AlertDialog.Builder builder2 = new AlertDialog.Builder(getActivity());

what does that error mean?

  • 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-09T11:19:35+00:00Added an answer on June 9, 2026 at 11:19 am

    It could be because you are trying to call getActivity() from within an onClick Listener. Typically Anonymous inner classes like to only access things that are final. Trying right before creating your listener to do something like

    final Context context = getActivity();
    

    and then use context instead of getActivity() on the line that crashes.

    And as a note. I would use DialogFragment here. It manages the lifecycle of your Dialog much better. Your going to run into issues when you try rotating the screen when the Dialog is open. However with the DialogFragment it will take care of this for you.

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

Sidebar

Related Questions

I have fragment that on a component click pop-ups DialogFragment. This dialog fragment holds
I have a Fragment that can create and pop up a DialogFragment, but when
I am trying to create a Custom dialog via DialogFragment. i want to have
I have decided that I wanted to create some custom dialog classes that could
I have an inner class to create and show a simple list dialog. private
Have a simple form that has a PictureBox in one location. I want to
I have created a custom dialog box extending the DialogFragment class. As stated in
I have created a custom dialog, the code is below. The problem is that,
I need to create a custom dialog fragment that works with all Android api
I am looking at using ActionbarSherlock but have one query that's holding me back.

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.