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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:17:00+00:00 2026-06-03T08:17:00+00:00

This is my first question on the site and I hope it’s not too

  • 0

This is my first question on the site and I hope it’s not too embarrassing. I’m making an Inventory tab for an Android game. I’ve declared static variables at the beginning of my class and based on whether or not the variables meet a requirement (the variable needs to be equal to at least one to show up in the inventory) I want to generate a string array that populates a list that will show you what is in your inventory. When I write the code in Eclipse, it tells me it’s error-free but when I try to run it in an Android emulator, I get an error and have to force exit. Here’s the code for reference.

(Sorry, if the code formatting is off. Nightly is an odd browser sometimes.)

    public class Inventory extends Activity {
    public static String selection = null;
    public static String IronS = "Iron";
    public static String WoodS = "Wood";
    public static String StoneS = "Stone";
    public static String WaterS = "Water";
    public static String ShieldRS = "Shield Rim";
    public static String ShieldBS = "Shield Base";
    public static String ShieldS = "Shield";
    public static String BladeS = "Blade";
    public static String SwordHS = "Sword Handle";
    public static String SwordS = "Sword";
    public static String BreastS = "Breastplate";
    public static String GauntS = "Gauntlets";
    public static String GreaveS = "Greaves";
    public static String RuneS = "Rune(s)";
    public static String FishingPS = "Fishing Pole";
    public static String PickS = "Pickaxe";
    public static String PickHS = "Pickaxe Head";
    public static int water = 1;
    public static int iron = 1;
    public static int stone = 1;
    public static int wood = 1;
    public static int shieldr, shieldb, shield, sword, swordh, blade, breast, gaunt, greave, rune, fishingp, pick, pickh;

    public static String[] CONTENTS;
    public static String[] MENU;

    public static int getWater() {
        return water;
    }
    public static void setWater(int water) {
        Inventory.water = water;
    }

    public static int getIron() {
        return iron;
    }
    public static void setIron(int iron) {
        Inventory.iron = iron;
    }

    public static int getWood() {
        return wood;
    }
    public static void setWood(int wood) {
        Inventory.wood = wood;
    }

    public static int getStone() {
        return water;
    }
    public static void setStone(int stone) {
        Inventory.stone = stone;
    }



    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
            if (getWater()>1)
                CONTENTS = new String []
                        {WaterS};
            if (getIron()>1)
                CONTENTS = new String []
                        {WaterS,IronS};
            if (getWood()>1)
                CONTENTS = new String []
                        {WaterS,IronS,WoodS};
            if (getStone()>1)
                CONTENTS = new String []
                        {WaterS,IronS,WoodS,StoneS};
            if (shieldr>1)
                CONTENTS = new String []
                        {WaterS,IronS,WoodS,WaterS,ShieldRS};
            if (shieldb>1)
                CONTENTS = new String []
                        {WaterS,IronS,WoodS,WaterS,ShieldRS,ShieldBS};
            if (shield>1)
                CONTENTS = new String []
                        {WaterS,IronS,WoodS,WaterS,ShieldRS,ShieldBS,ShieldS};
            if (sword>1)
                CONTENTS = new String []
                        {WaterS,IronS,WoodS,WaterS,ShieldRS,ShieldBS,ShieldS,SwordS};
            if (swordh>1)
                CONTENTS = new String []
                        {WaterS,IronS,WoodS,WaterS,ShieldRS,ShieldBS,ShieldS,SwordS,SwordHS};
            if (blade>1)
                CONTENTS = new String []
                        {WaterS,IronS,WoodS,WaterS,ShieldRS,ShieldBS,ShieldS,SwordS,SwordHS,BladeS};
            if (breast>1)
                CONTENTS = new String []
                        {WaterS,IronS,WoodS,WaterS,ShieldRS,ShieldBS,ShieldS,SwordS,SwordHS,BladeS,
                         BreastS};
            if (gaunt>1)
                CONTENTS = new String []
                        {WaterS,IronS,WoodS,WaterS,ShieldRS,ShieldBS,ShieldS,SwordS,SwordHS,BladeS,
                         BreastS,GauntS};
            if (greave>1)
                CONTENTS = new String []
                        {WaterS,IronS,WoodS,WaterS,ShieldRS,ShieldBS,ShieldS,SwordS,SwordHS,BladeS,
                         BreastS,GauntS,GreaveS};
            if (rune>1)
                CONTENTS = new String []
                        {WaterS,IronS,WoodS,WaterS,ShieldRS,ShieldBS,ShieldS,SwordS,SwordHS,BladeS,
                         BreastS,GauntS,GreaveS,RuneS};
            if (fishingp>1)
                CONTENTS = new String []
                        {WaterS,IronS,WoodS,WaterS,ShieldRS,ShieldBS,ShieldS,SwordS,SwordHS,BladeS,
                         BreastS,GauntS,GreaveS,RuneS,FishingPS};
            if (pick>1)
                CONTENTS = new String []
                        {WaterS,IronS,WoodS,WaterS,ShieldRS,ShieldBS,ShieldS,SwordS,SwordHS,BladeS,
                         BreastS,GauntS,GreaveS,RuneS,FishingPS,PickS};
            if (pickh>1)
                CONTENTS = new String []
                        {WaterS,IronS,WoodS,WaterS,ShieldRS,ShieldBS,ShieldS,SwordS,SwordHS,BladeS,
                         BreastS,GauntS,GreaveS,RuneS,FishingPS,PickS,PickHS};
            if (stone>1)
                CONTENTS = new String []
                        {WaterS,IronS,WoodS,WaterS,ShieldRS,ShieldBS,ShieldS,SwordS,SwordHS,BladeS,
                         BreastS,GauntS,GreaveS,RuneS,FishingPS,PickS,PickHS,StoneS};
            Arrays.sort(CONTENTS);
    }


}

When I remove the if statements and just leave the array, there are no problems. It compiles as usual and I can insert the array into a ListView. I’ve been banging away at this for a while and have tried making switch/case statements instead of the ifs but it didn’t work correctly (wouldn’t take multiple variables into account for conditions). If-else-if didn’t work, because the statements wouldn’t continue to the preceding conditions if a true value was found.

I’m very new at this, so I have no idea how to precede. i can’t think of another way to populate an inventory list without conditionals evaluating if items even “exist” (in the game).

  • 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-03T08:17:02+00:00Added an answer on June 3, 2026 at 8:17 am

    You have a logical error not a syntactical one.

    These integers are null

    public static int shieldr, shieldb, shield, sword, swordh, blade, breast, gaunt, greave, rune, fishingp, pick, pickh;
    

    and you are trying to evaluate them

    if (shieldr>1)
                    CONTENTS = new String []
                            {WaterS,IronS,WoodS,WaterS,ShieldRS};
                if (shieldb>1)
                    CONTENTS = new String []
                            {WaterS,IronS,WoodS,WaterS,ShieldRS,ShieldBS};
                if (shield>1)
                    CONTENTS = new String []
                            {WaterS,IronS,WoodS,WaterS,ShieldRS,ShieldBS,ShieldS};
    
    ...
    ...
    

    This would throw a null exception your variables need values before you use them in expressions.

    Have fun !

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

Sidebar

Related Questions

This is my first time posting a question on this site, but certainly not
This is my first question, but I've already found this site extremely helpful, so
This is my first question. Thanks to everyone who contributes to this site, it's
this is my first question.. so, here we go. i have a site, 100%
though I have visited this site many times, this is my first question. After
This is my first question on Stack Overflow, so I hope that I'm clear
this is my first question to SO so i'll try not to disgrace myself.
My first post on this site with huge hope:: I am trying to understand
I have a question about Excel! I hope that isn't too unconventional for this
this is the first question I post in this site, so you have to

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.