我有2個分類在不同的頁面。Enum無法解析? Java
對象類:
public class Sensor {
Type type;
public static enum Type
{
PROX,SONAR,INF,CAMERA,TEMP;
}
public Sensor(Type type)
{
this.type=type;
}
public void TellIt()
{
switch(type)
{
case PROX:
System.out.println("The type of sensor is Proximity");
break;
case SONAR:
System.out.println("The type of sensor is Sonar");
break;
case INF:
System.out.println("The type of sensor is Infrared");
break;
case CAMERA:
System.out.println("The type of sensor is Camera");
break;
case TEMP:
System.out.println("The type of sensor is Temperature");
break;
}
}
public static void main(String[] args)
{
Sensor sun=new Sensor(Type.CAMERA);
sun.TellIt();
}
}
主要類:
import Sensor.Type;
public class MainClass {
public static void main(String[] args)
{
Sensor sun=new Sensor(Type.SONAR);
sun.TellIt();
}
錯誤有兩個,一個是類型解決不了另一種是不傾斜導入。我能做什麼?我第一次使用枚舉,但你看到。
查看Reimeus的答案應該被接受(包含'enum'的類不能在默認包中)。或[看這裏](http://stackoverflow.com/questions/283816/how-to-access-java-classes-in-the-default-package)。 – mins