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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:33:43+00:00 2026-05-15T19:33:43+00:00

I tried printStackTrace and I have coverted everything to static (I think)… however, lines

  • 0

I tried printStackTrace and I have coverted everything to static (I think)… however, lines 17 and line 38 are the problem… because of this error:

You picked up: Pickaxe
java.lang.NullPointerException
        at item.addInv(item.java:38)
        at item.main(item.java:17)
Description: Can be used to mine with.
Press any key to continue . . .

Line 17: anItem.addInv(1);

Line 38: arr.add("Dan");

And here is my code:

import java.io.*;
import java.util.*;
import javax.swing.*;

public class item
{
    public static int attack, defense;
    public static ArrayList<String> arr;
    public static String name, desc, typeOf, attackAdd, defenseAdd, canSell, canEat,earnedCoins,canEquip;

    String stats[];

    public static void main(String args[])
    {
        item anItem = new item();
        ArrayList<String> arr = new ArrayList<String>();
        anItem.addInv(1);
    }

    public static void addInv(int e) {
        String iname = getItem(1)[0];
        String idesc = getItem(1)[1];
        int itypeOf = Integer.parseInt(getItem(1)[2]);
        int iattackAdd = Integer.parseInt(getItem(1)[3]);
        int idefenseAdd = Integer.parseInt(getItem(1)[4]);
        boolean icanSell = Boolean.parseBoolean(getItem(1)[5]);
        boolean icanEat = Boolean.parseBoolean(getItem(1)[6]);
        int iearnedCoins = Integer.parseInt(getItem(1)[7]);

        attack = attack + iattackAdd;
        defense = defense + idefenseAdd;
        System.out.println("You picked up: " + iname);
        try {
            arr.add("Dan");
        } catch(NullPointerException ex) {
            ex.printStackTrace();
        }

        System.out.println("Description: " + idesc);
    }

    public static String[] getItem(int e) {

        String[] stats = new String[7];

        String name = "Null";
        String desc = "None";
        String typeOf = "0";
        String attackAdd = "0";
        String defenseAdd = "0";
        String canSell = "true";
        String canEat = "false";
        String earnedCoins = "0";

        if (e == 1) {
            name = "Pickaxe";
            desc = "Can be used to mine with.";
            typeOf = "2";
            attackAdd = "2";
            earnedCoins = "5";
        }

        return new String[] { name, desc, typeOf, attackAdd, defenseAdd, canSell, canEat, earnedCoins};
    }
}

As you can see, it’s those lines and I don’t know what to do… :\

  • 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-15T19:33:43+00:00Added an answer on May 15, 2026 at 7:33 pm

    String canEat = "false"; Why are you converting to and from strings?

    You seem to have muddled an item class an inventory class.

    Perhaps an Enum would be better:

    public enum InventoryItem
    {
        PICKAXE("Pickaxe", "Can be used to mine with", ItemType.Tool,
                5, 2, 0)
    
        EPIC_PICKAXE("Super mega awesome Pickaxe", "Can be used to mine with, but epically", ItemType.Tool,
                1000000, 100, 0)
    
    
        public static enum ItemType {
            TOOL,
            WEAPON
        }
    
        public final String name, description;
        public final ItemType type;
        public final boolean canSell, canEat, canEquip;
        public final int earnedCoins, attackAdd, defenseAdd;
    
        private InventoryItem(String name, String description, ItemType type
                              int earnedCoins, int attackAdd, int defenseAdd,
                              boolean canSell, boolean canEat, boolean canEquip)
        {
            this.name        = name;
            this.description = description;
            this.type        = type
            this.canSell     = canSell;
            this.canEat      = canEat;
            this.canEquip    = canEquip;
            this.earnedCoins = earnedCoins;
        }
    
        private InventoryItem(String name, String description, ItemType type
                              int earnedCoins, int attackAdd, int defenseAdd)
        {
            this(name, description, type,
                 earnedCoins, attackAdd, defenseAdd,
                 true, false, true);
        }
    }
    

    Then you can just have List<InventoryItem> inventory = new ArrayList<InventoryItem>() within your player’s class, and directly interface with that.

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

Sidebar

Related Questions

I just started with the connectivity and tried this example. I have installed the
I have tried looking for an answer to this on other threads, but so
I have now tried to make this work for two days with two different
Tried searching the site, but cannot find an answer to my problem: Lets say
Tried to search for this online and didn't get very far, so I'm asking
Tried this: $('.link').click(function(e) { $.getScript('http://www.google.com/uds/api?file=uds.js&amp;v=1.0', function() { $('body').append('<p>GOOGLE API (UDS) is loaded</p>'); }); return
Tried examples from 'php.net' but don't understand what's the problem. Any suggestions? <?php $_SESSION['test']
I have a problem with KSOAP2 for android with dependencies on an Android device.
I have got a problem here in terminating the threads. The problem is that
I have two functions that access the internet on the APP start. I've tried

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.