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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:19:48+00:00 2026-05-29T04:19:48+00:00

i use setMultiChoiceItems for a list in a dialog. when click on ok the

  • 0

i use setMultiChoiceItems for a list in a dialog.
when click on ok the code is

 .setPositiveButton(R.string.alert_remove, new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which){
String[] res = null;
for(int i=-1,l=usrCats.length; ++i<l;){
    if(selections[i])
       res[i] = usrCats[i].toString();
}
if(res != null && res.length>0)
   dbManager.removeUserShoppingCategories(res);
}       
})

i want to check if an item is selected with if(selections[i] and if so, add the name in a
String

i am having a null pointer access in the res[i] = usrCats[i].toString() and a dead code warning in the last if statement.

i am using the last if, to check if there has been any selection so as to call my method.

what am i doing wrong?

  • 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-29T04:19:50+00:00Added an answer on May 29, 2026 at 4:19 am
            .setPositiveButton(R.string.alert_remove, new DialogInterface.OnClickListener(){
            public void onClick(DialogInterface dialog, int which){
            String[] res = null; // you initialised it with null
            for(int i=-1,l=usrCats.length; ++i<l;){ /*this line and the below line are condition 
        statemnts whose code may not run. so there are chances that your **res** will 
        remain initialised with null*/
                if(selections[i])
                   res[i] = usrCats[i].toString();
            }
            if(res != null && res.length>0)// so here it shows a dead code warning.
               dbManager.removeUserShoppingCategories(res);
            }       
            })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

use Rack::Static, :urls => ['/stylesheets', '/images'], :root => 'public' run proc { |env| [200,
Use Case I need to package up our kml which is in a String
use Control::CLI; $cli = new Control::CLI('SSH'); $cli->connect(Host=>'10.10.10.10',Username=>'user',Password=>'pwd'); $cli->waitfor('>'); $cli->print('Show XXXXXXXXXXXXXXXXXXXX| grep Active'); @f=$cli->waitfor('>'); print
use WWW::Mechanize; my $mech = WWW::Mechanize->new; $mech->get( $url ); say $mech->text; How could I
I have created a dialog that shows a multi-choice list of items that can
use Parallel::ForkManager; use LWP::Simple; my $pm=new Parallel::ForkManager(10); our $a =0; @LINK=( 10,203, 20, 20
I use Qt 4.4.2 in Visual Studio 2008. When I am writing code, IntelliSense
use case is simple: I want to run some boiler plate code before each
Use new MediaPlayer by Yahoo. Content parse automatic - greate, but I use ajax
'''use Jython''' import shutil print dir(shutil) There is no, shutil.move, how does one move

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.