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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:55:20+00:00 2026-05-27T01:55:20+00:00

I am trying to write a dialog box in my app . The problem

  • 0

I am trying to write a dialog box in my app . The problem is when i click the OK (SetPositiveButton) it is showing the following Runtime Error

E/AndroidRuntime(702): java.lang.ArrayIndexOutOfBoundsException

If i am trying to execute the commented lines in the below code , But it works fine in the onClick but showing some Kind of Bug for setPositiveButton

   @Override
protected Dialog onCreateDialog(int id) {
    switch(id){

 case ONCLICK_EXTRAS:
     return new AlertDialog.Builder(AcricklayoutActivity.this)
     .setIcon(R.drawable.ic_launcher)
     .setTitle("Extras")
     .setSingleChoiceItems(R.array.extras, 0, new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int which) {
             String[] items = getResources().getStringArray(R.array.extras);
             value = items[which];
             Log.v("this",String.valueOf(which)+items[which]);
         }
     })
     .setPositiveButton("OK", new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int which) {
            // String[] items = getResources().getStringArray(R.array.extras);
            //text.setText(items[which]);
            // Log.v("this",String.valueOf(which)+items[which]);

         }
     })
     .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int which) {


         }
     })
    .create();

I will explain my code here

  1. I am trying to use an String array from the Resource/values file to populate my AlertDialogbox ,
  2. And Storing that into the Static String variable value

it works fine till the positive button click of the dialog activity after that app gets crashed.. Can anyone Help me in this issue ???

Thanks in Advance !!

  • 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-05-27T01:55:21+00:00Added an answer on May 27, 2026 at 1:55 am
     public void onClick(DialogInterface dialog, int which) { 
    

    This which in this method tells the button which was clicked, and you should not be using it as index for your arrays. which can be any of these:

    Dialog.BUTTON_NEGATIVE; (value=-2)
    
    Dialog.BUTTON_NEUTRAL;  (value=-3)
    
    Dialog.BUTTON_POSITIVE   (value=-1)
    

    Naturally if you use it for getting values from array, it will give you ArrayIndexOutOfBoundsException

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

Sidebar

Related Questions

I am trying to write a custom dialog box that takes a name from
I'm trying to write a resolution selection dialog that pops up when a program
im trying to write an app that will display a list off lines from
I'm trying to write a custom in-window confirm dialog (based on jQuery UI) that
I'm trying to use the GetOpenFileName() common dialog box call to pop open a
I am trying to create a simple dialog box to allow my user to
I am trying to write save as dialog with javascript, I have a content
In trying to write more testable Java code, I have been using the Model-View-Presenter
I am trying to write a simple dialog that is called by the flash
I'm trying to write a simple Java game. I have a NPC class, with

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.