else
throw new ExceptionLogicMalformedSignal(c, "Invalid character!");
在fromString(char c)
方法中。我在代码中做错了什么?为什么会发生非列表方法?提前谢谢!
import java.util.LinkedList;
import java.util.List;
public enum Signal {
HI, LO, X;
public Signal invert()
{
if(this == HI)
return LO;
else if(this == LO)
return HI;
else if(this == X)
return X;
return this;
}
public static Signal fromString(char c)
{
if(c == '1')
return HI;
else if(c == '0')
return LO;
else if(c == 'X')
return X;
else if(c == 'x')
return X;
else
throw new ExceptionLogicMalformedSignal(c, "Invalid character!");
}
public List <Signal> fromString(String inps)
{
List<Signal> values = new LinkedList<Signal>();
if(inps.equals("1"))
values.add(HI);
else if(inps.equals("0"))
values.add(LO);
else if(inps.equals("X"))
values.add(X);
else if(inps.equals("x"))
values.add(X);
else
throw new ExceptionLogicMalformedSignal(inps.charAt(0), "Invalid character!");
return values;
}
@Override
public String toString()
{
if(this == HI)
return "1";
else if(this == LO)
return "0";
else if(this == X)
return "X";
return "Error here!";
}
}
public class ExceptionLogicMalformedSignal extends RuntimeException {
private char bad; //offending character
private String msg = "You entered an invalid character"; //the entire message you want to convey
public ExceptionLogicMalformedSignal(char bad, String msg)
{
this.bad = bad;
this.msg = msg;
}
@Override
public String toString()
{
return msg;
}
public String getBad()
{
String value = Character.toString(this.bad);
return value;
}
public String msg()
{
return msg;
}
public void setBad(String bad)
{
String value = Character.toString(this.bad);
value = bad;
}
public void setMsg(String msg)
{
this.msg = msg;
}
}
答案 0 :(得分:2)
List cannot be resolved to a type
是一个编译器错误。在抛出异常之后你就得不到它了#39;在编译使用List.
你需要
import java.util.List;
尽管你发布了什么,但显然它不存在。