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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:43:55+00:00 2026-05-31T20:43:55+00:00

I’m having some trouble with the logic behind storing an ImageView into an ArrayList.

  • 0

I’m having some trouble with the logic behind storing an ImageView into an ArrayList.

The application I’m developing keeps track of player statuses in a game. The user first adds Player objects (which keeps track of a status string and a status image to go with it) to an ArrayList (to keep track of them all). Then, after submitting all of the players, a screen pops up inflating a TableRow for each player, containing a button (to view the Player’s profile), an ImageView (an icon representing the status), and a TextView (containing the player’s status string value).

I don’t have a problem with the buttons and loading each player’s profile. The problem occurs with loading the “select status” GUI from dialog_select_icon.xml, particularly the ImageView ArrayList. I get a NullPointerException, which doesn’t make sense to me because I’m doing it essentially the same way as I did the buttons.

//this code runs when user clicks a player's status icon
public void playerStatusIconClicked(View v)
{
    //loop through buttons to determine which player's button was clicked
    for (int i = 0; i < playerList.size(); i++)
    {
        if (v.getId() == playerStatusIVList.get(i).getId())
        {
            calledPlayer = i; //instance variable
            loadStatusIconGUI();
        }//if
    }//for
}//method playerStatusIconClicked


//showStatusIconGUI inflates the "select status icon" GUI
//and handles the user selecting an icon
private void loadStatusIconGUI()
{       
    //inflate the GUI for the showStatusIcon dialog (inflater is an instance variable)
    View view = inflater.inflate(R.layout.dialog_select_icon, null);
    //if the list has something in it, start from fresh
    if (!selectStatusIVList.isEmpty())
    {
        selectStatusIVList.clear();        
    }

    //list of icons in the "select status icon" dialog
    selectStatusIVList.add((ImageView) statusIconGUI.findViewById(R.id.statusIV0));
    selectStatusIVList.add((ImageView) statusIconGUI.findViewById(R.id.statusIV1));
    selectStatusIVList.add((ImageView) statusIconGUI.findViewById(R.id.statusIV2));
    selectStatusIVList.add((ImageView) statusIconGUI.findViewById(R.id.statusIV3));
    selectStatusIVList.add((ImageView) statusIconGUI.findViewById(R.id.statusIV4));
    selectStatusIVList.add((ImageView) statusIconGUI.findViewById(R.id.statusIV5));
    selectStatusIVList.add((ImageView) statusIconGUI.findViewById(R.id.statusIV6));

    //create a dialog so user can select an icon
    AlertDialog.Builder selectIconDialog = new AlertDialog.Builder(this);
    selectIconDialog.setView(view); //set the Dialog's custom view
    selectIconDialog.setTitle(R.string.title_select_icon);

    selectIconDialog.setNegativeButton(R.string.close, null);
    selectIconDialog.show();
}//showStatusIconGUI


//Handle clicks in the "select status icon" dialog
//Assigns a new status to the player
public void statusIconClicked(View v)
{
    Toast message;

    for (int i = 0; i < selectStatusIVList.size(); i++)
    {
        if (v.getId() == selectStatusIVList.get(i).getId())
        {
            message = Toast.makeText(
                MafiaTracker.this, "new status: " statusID[i], Toast.LENGTH_SHORT);
            message.show();
            playerList.get(calledPlayer).setImage(imageID[i]);
            playerList.get(calledPlayer).setStatus(statusID[i]);
        }
    }

    updateViewPlayerGUI(); 
}

Note that imageID[i] and statusID[i] are referring to int arrays containing the IDs for each status string and status image.

I can post the xml file but since it’s 124 lines long I’d prefer not to. Just know that each ImageView in the xml file DOES have an ID, so I can’t figure out why I’m getting these NullPointerExceptions, starting with the “if (!selectStatusIVList.isEmpty())” part, and continuing on with every other call after.

Please help!

  • 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-31T20:43:56+00:00Added an answer on May 31, 2026 at 8:43 pm

    statusIconGUI seems to be the main layout xml you used in setContenView().
    Consider the line :

    selectStatusIVList.add((ImageView) statusIconGUI.findViewById(R.id.statusIV0));
    

    you are using findViewbyID on statusIconGUI. Do that instead on the view instance of R.layout.dialog_select_icon which you inflated.
    so, change the above line to :

    selectStatusIVList.add((ImageView) view.findViewById(R.id.statusIV0));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I am currently running into a problem where an element is coming back from

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.