“Non-static method cannot be referenced from a static context” error

I have a class named Media which has a method named setLoanItem:

public void setLoanItem(String loan) {
    this.onloan = loan;
}

I am trying to call this method from a class named GUI in the following way:

public void loanItem() {
    Media.setLoanItem("Yes");
}

But I am getting the error

non-static method setLoanItem(java.lang.String) cannot be referenced from a static context

I am simply trying to change the variable onloan in the Media class to "Yes" from the GUI class.

I have looked at other topics with the same error message but nothing is clicking!

69
задан Nathan Hughes 4 May 2017 в 11:32
поделиться