Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I'm creating a Java code and keep getting this error > TestClass.java:26: error: non-static method isEmpty(LetterInventory) cannot be referenced from a static context I have

I'm creating a Java code and keep getting this error >

TestClass.java:26: error: non-static method isEmpty(LetterInventory) cannot be referenced from a static context



I have code from 2 separate Java files that are conflicting.

For the first file, LetterInventory, it compiles without issue. I have:

public int size() {       return size;    } // end size    // If Letter Inventory is empty, returns true.  // If Letter Inventory is not empty, returns false.    public boolean isEmpty(LetterInventory p) {       if(size == 0) {          return true;       }       return false;



The 2nd file, TestClass, is the one giving me the error:

String insert = scan.next();       LetterInventory v = new LetterInventory(insert);       if(LetterInventory.isEmpty(v)) {

There are a few more pieces of code surrounding it, but it's mostly println's, so I don't think it has anything to do with it.


Please help! If you could also give an example of what would work in the code, that would be amazin.g

Step by Step Solution

There are 3 Steps involved in it

Step: 1

The error message youre encountering indicates that youre trying to call a nonstatic method isEmpty ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Programming With Java A Problem Solving Approach

Authors: John Dean

3rd International Edition

1260575241, 9781260575248

More Books

Students also viewed these Programming questions

Question

Learn the techniques of designing a killer Web site. P-698

Answered: 1 week ago

Question

Was the experimental treatment described in sufficient detail?

Answered: 1 week ago