Question: I'm creating a Java code and it keeps going back and forth between 2 errors > Error #1: TestClass.java:26: error: non-static method isEmpty(LetterInventory) cannot be
I'm creating a Java code and it keeps going back and forth between 2 errors >
Error #1:
TestClass.java:26: error: non-static method isEmpty(LetterInventory) cannot be referenced from a static context
Error #2:
TestClass.java:26: error: method isEmpty in class LetterInventory cannot be applied to given types; if(v.isEmpty()) { ^
There are 2 Java files causing the conflict: File #1 LetterInventory (compiles without issue) and File #2 TestClass (the one getting the error codes).
The first error code results from these programs:
I have code from 2 separate Java files that are conflicting.
File #1:
public int size() { return size; } public boolean isEmpty(LetterInventory p) { if(size == 0) { return true; } return false; } File #2:
String insert = scan.next(); LetterInventory v = new LetterInventory(insert); if(LetterInventory.isEmpty(v)) {
I changed File #2 up SLIGHTLY, and that's when I got the 2nd error code:
New File #2:
public static void main (String[] args) { System.out.println("This is to the Letter Inventory!"); System.out.println("Please type a word of one or more characters: "); String insert = scan.next(); LetterInventory v = new LetterInventory(insert); if(v.isEmpty()) { System.out.println("Please include at least one character."); insert = scan.next(); v = new LetterInventory(insert); }
Please help! If you could also give an example of what would work in the code, that would be amazing
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
