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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:24:38+00:00 2026-06-10T08:24:38+00:00

Just making a little android app, and I need to hold a collection of

  • 0

Just making a little android app, and I need to hold a collection of data, and not sure if I should use an object, array, listarray, hashmap, etc.

It needs to be able to store strings and integers (eg tamename, score, category, number of turns).

It needs to be able to store a variable number of teams.

Currently having issues where I try to store it as an object, but it wont lt me increment the score int value.

Which collection should I use for this instance, and when should I use each one in other instances?

EDIT

Ok so did that, but I keep getting NullPointerException when i try to access / increment it. I can only assume it cant access the teams var properly from upScore

So my onCreate is like this

public ArrayList<Team> teams;
public int currentTeam;

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_game);

    currentTeam = 0;

    List<Team> teams = new ArrayList<Team>();

    teams.add(new Team("Team 1"));
    teams.add(new Team("Team 2"));

}

then upScore gets called when a button is pressed. the fatal exception is on this line

public void upScore(int team_key) {
    teams.get(0).score++;
}

And here is my Team object

class Team {
    public String name;
    public int score;
    public String category;
    public int turns;

    public Team (String teamName) {
        name = teamName;
    }
}
  • 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-10T08:24:40+00:00Added an answer on June 10, 2026 at 8:24 am

    Create your own class that represents objects which can hold the data you need, something like:

    class Team
    {
        public String teamName;
        public int score;
        public String category;
        public int numberOfTurns;
    
        public Team(...){...} // the constructor
    }
    

    Then use any data structure you want, for example, an arraylist:

    List<Team> list = new ArrayList<Team>();
    

    To add elements to the list:

    list.add(new Team(...));
    

    To increment the score of the first team in the list:

    list.get(0).score++;
    

    and so on…

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

Sidebar

Related Questions

Hello guys i'm making a little app in which i need to enumerate all
So I'm just making a small little app for personal reasons. Basically all it
I'm making a little alarm clock as a project to practice as I'm just
I'm making myself a little messenger just for fun. And I want to make
I am not overly competent in C++ and this compiler error is just making
I'm making a little web based game and need to determine where to put
Hello i'm working on an app where i'm basically just making a custom multi
I've just started learning Android development and as a little project, I'm building a
Hey, I've just started learning JavaScript and I'm making a little script that generates
I am currently toying around with android and making a little bit of a

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.