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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T21:48:56+00:00 2026-05-15T21:48:56+00:00

I know this error very well however this is the once time I’m stumped.

  • 0

I know this error very well however this is the once time I’m stumped. I know that I can’t call non-static variables from main method but this is confusing. Maybe you can help? That error is show on addInv(1); line…

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[])
        {

            addInv(1);

        }

public 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);
arr.add("dan");
System.out.println("Description: " + idesc);

}

            // Types of Items
            // 0 - Weapon
            // 1 - Food
            // 2 - Reg Item
            // 3 - Helmet
            // 4 - Armor Legs
            // 5 - Chest Armor
            // 6 - Shield

        public 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};

    }

}

Thanks.

  • 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-15T21:48:57+00:00Added an answer on May 15, 2026 at 9:48 pm

    You can’t call a non static method from a static method. So either make addInv static:

    public class Item {
        ...
    
        public static void main(String args[]) {
            addInv(1);
        }
    
        public static void addInv(int e) {
            ...
        }
    
        public static String[] getItem(int e) {
            ...
        }
    }
    

    But making all these methods static may not be an appropriate design, you might prefer using an Item instance in your main:

    public class Item {
        ...
    
        public static void main(String args[]) {
            Item item = new Item();
            item.addInv(1);
        }
    
    }
    

    By the way, I don’t mean to be rude but you should seriously work on your (awful) code formatting and conventions, both for readers and for you.

    See also

    • Code Conventions for the Java Programming Language
    • How to Write Doc Comments for the Javadoc Tool
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I know that there is a very similar question to this all over
Well, I know this is another newbie question but I'm very frustrated and I'm
I do ActionScript 3.0 programming and I know that very well. I have a
I know this error appeared on forum million of times, but please help me
I know what this error means, the unusual thing it whats throwing it. EntitySave(arguments.entity);
Anyone know what this error means? after googling I found a bunch of sites
I know what this error is, how to fix it, etc. My question is
Does anyone know what this error message means? FATAL: Code generation error detected during
I know this is a common error, but bear with me. I've pursued the
I know this is a pretty common error, usually having to do with the

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.