我如何使这两个错误消失?在java中的价值



我在这两个小错误中遇到了一些挣扎,因为Eclipse IDE"这样说"。我会指出错误。老实说,我不知道如何深入解释这些错误。我以为它们很简单,我无法遇到错误。

    ScheduledExecutorService timer = Executors.newScheduledThreadPool (1);
    timer.scheduleAtFixedRate(new Runnable() 
    {
        public void run() 
        {
            if (lists. size ()> 0) 
            {
                boolean lighted = Lamp.valueOf(Road.this.name).isLighted(); //According to Eclipse, "The method valueOf(Class<T>, String) in the type Enum<Lamp> is not applicable for the arguments (String)"
                if (lighted) 
                {
                    System.out.println(lists.remove(0) + "is traversing!");
                }
            }
        }
    }, 1,1, TimeUnit. SECONDS);

和我的不同类中的另一个错误我的软件包

public Lamp Blackout() 
{
    this.lighted = false;
    if (opposite != null) 
    {
        Lamp.valueOf(opposite).in.Blackout(); //in cannot be resolved or is not a field. It suggests me to create enum constant, which I did and it wouldn't work either. 
    }
    Lamp nextLamp = null;
    if (next != null) 
    {
        nextLamp = Lamp.valueOf(next);
        System.out.println("Green" + name () + "--------> switch to" + next);
        nextLamp.light();
    }
    return nextLamp;
}

您的第一个错误 Lamp.valueOf(Road.this.name).isLighted();

//根据eclipse,"方法值(class,string) 类型枚举不适用于参数(字符串)"

方法lamp.valueof()期望两个参数,首先是一个类参数&amp;然后是字符串参数。您刚刚通过了该方法中的字符串参数,这就是Eclipse抛出错误的原因。

您第二个错误

Lamp.valueOf(opposite).in.Blackout();

//无法解决或不是字段。

对我来说,它看起来像是不正确的语法。彻底检查您的代码。在您的代码方法中,正在链接。in不应该在那里。否则可能是一种方法in()

在黑暗中拍摄,因为您尚未披露所有相关代码,但是您可以尝试在此处添加valueOf的丢失参数:

boolean lighted = Lamp.valueOf(Lamp.class, Road.this.name).isLighted();

并在此处调用in() 方法

Lamp.valueOf(Lamp.class, opposite).in(Blackout());

请遵循Java代码样式约定;方法名称应以小写字母开头,因此停电方法签名应该看起来像这样:

public Lamp blackout()

没有看到Lamp enum的代码,就不可能知道后一种情况的确切问题是什么。

最新更新