0

I cannot figure out what I have done wrong in the following code segment:

private Door openOtherDoor(Door prizeDoor, Door selectedDoor){
Door.setPrize(prizeDoor.doorPrize);
Door.open(selectedDoor.doorPrize);

I am getting the following error:

Cannot make a static reference to the non-static method open(boolean) from the type Door

Any help would be greatly appreciated

  • 1
    The method `open` is not static, but you are calling it from a static method. Change the method to `public static void open(boolean b)` – ruyili Jan 31 '16 at 20:58
  • Almost certainly not. You should call `this.open()` instead of `Door.open()`. If you make it static you won't know which `Door` to open. @TheCoffeeKid – user207421 Jan 31 '16 at 21:29
  • Oh, didn't know that :P – ruyili Jan 31 '16 at 21:35

2 Answers2

-1

if those methods are in the class Door, then you can do

private Door openOtherDoor(Door prizeDoor, Door selectedDoor){
Door.setPrize(prizeDoor.doorPrize);
Door.open(selectedDoor.doorPrize);

if setPrize is an static method, otherwise you will need the instance method i.e

private Door openOtherDoor(Door prizeDoor, Door selectedDoor){
    this.setPrize(prizeDoor.doorPrize);
    this.open(selectedDoor.doorPrize);
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
-1

According to error. You should define open method in Door class as static.

eg04lt3r
  • 2,467
  • 14
  • 19