为什么这段代码给出了一个“Unreachable Statement"?错误? [英] Why is this code giving an "Unreachable Statement" error?

查看:26
本文介绍了为什么这段代码给出了一个“Unreachable Statement"?错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码,我收到了一个无法访问的语句错误,但我不知道为什么.

This is my code and im getting an unreachable statement error on it but i do not know why.

public boolean Boardload(String[] args) throws Exception
{
    Robot robot = new Robot();
    Color color3 = new Color(114, 46, 33);
    Color color4 = new Color(180, 0, 0);

    {
        Rectangle rectangle = new Rectangle(0, 0, 1365, 770);

        {
            while(false)
            {
                BufferedImage image = robot.createScreenCapture(rectangle);
                search: for(int x = 0; x < rectangle.getWidth(); x++)
                {
                    for(int y = 0; y < rectangle.getHeight(); y++)
                    {
                        if(image.getRGB(x, y) == color3.getRGB())
                        {
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    }
} 

确切的错误是:

java:68: unreachable statement
         {
         ^

帮助会很好,这段代码应该循环直到找到像素.

Help would be nice, this code is supposed to loop until the pixel is found.

推荐答案

我认为问题在于你的循环是

I think the problem is that your loop is

while(false) {

这个循环永远不会执行,因为false != true.因此,Java 编译器会告诉您循环体中的任何内容都不会执行,因此无法访问.

This loop never executes, because false != true. Consequently, the Java compiler is telling you that nothing in the body of the loop will ever execute, and hence it's unreachable.

尝试将循环更改为

while (true) {

(惯用的永远循环")看看是否能解决问题.

(the idiomatic "loop forever") and see if that fixes things.

希望这有帮助!

这篇关于为什么这段代码给出了一个“Unreachable Statement"?错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆