【问题标题】:Cannot find symbol compiler error找不到符号编译器错误
【发布时间】:2014-07-01 10:56:04
【问题描述】:

我在完成 Java 编程课程的作业时遇到了问题。我要做的是对具有纯色背景的图像执行色度键技术。更多信息可以找到here。当我为该方法放置两个对象参数时,我创建的方法有效。但是,当我将参数放入构造函数中,然后尝试使用该方法时,会出现编译器错误。我在下面有我的类(我必须使用两个不同的类,一个用于方法,一个用于测试)。任何帮助将不胜感激,我是 java 新手,最简单的路线是最好的。

public class ChromaKey
{
    public ChromaKey(Picture backgroundDelete, Picture backgroundImage)
    {  
    }
    public void chromaKey()
    {        
         int redValue = 0; int greenValue = 0; int blueValue = 0;      
        Color pixelColor = null;   
        Color pixelColor1 = null;   
        for(int y = 0; y < backgroundImage.getHeight(); y++)             
        {
            for(int x = 0; x < backgroundImage.getWidth(); x++)    
            {
                Pixel targetPixel = new Pixel(backgroundImage,x,y);   
                Pixel targetPixel1 = new Pixel(backgroundDelete,x,y);

                targetPixel = backgroundImage.getPixel(x,y);                
                pixelColor = targetPixel.getColor();

                targetPixel1 = backgroundDelete.getPixel(x,y);
                pixelColor1 = targetPixel1.getColor();

                int targetRed = pixelColor1.getRed();
                int targetBlue = pixelColor1.getGreen();
                int targetGreen = pixelColor1.getBlue();

                int backgroundRed = pixelColor.getRed();
                int backgroundGreen = pixelColor.getGreen();
                int backgroundBlue = pixelColor.getBlue();

                if(targetRed >= 200 && targetBlue >= 200 && targetGreen >= 200) 
                {
                    targetPixel1.setRed(backgroundRed);
                    targetPixel1.setGreen(backgroundGreen);
                    targetPixel1.setBlue(backgroundBlue);

                }
            }
        }
        backgroundImage.show();
        backgroundDelete.show();
    }
}

【问题讨论】:

  • 编译时错误是什么?
  • 在您的示例中,backgroundDeletebackgroundImage 似乎没有被初始化。那是你正在使用的真实课程吗?

标签: java constructor find symbols


【解决方案1】:

有些东西看起来好像不见了。首先,您是在导入 Color 和 Pixel 类,还是将它们与您的 ChromaKey 类包含在同一个包中?

其次,您需要将 backgroundImage 和 backgroundDelete 定义为类变量,以便在您的 void chromaKey() 方法中调用它(注意我添加的“private Picture backgroundDelete;”行以及构造函数中的赋值):

公共类 ChromaKey {

private Picture backgroundDelete;
private Picture backgroundImage;


public ChromaKey(Picture backgroundDelete, Picture backgroundImage)
{  
    this.backgroundDelete = backgroundDelete;
    this.backgroundImage = backgroundImage;
}
public void chromaKey()
{        
     int redValue = 0; int greenValue = 0; int blueValue = 0;      
    Color pixelColor = null;   
    Color pixelColor1 = null;   
    for(int y = 0; y < backgroundImage.getHeight(); y++)             
    {
        for(int x = 0; x < backgroundImage.getWidth(); x++)    
        {
            Pixel targetPixel = new Pixel(backgroundImage,x,y);   
            Pixel targetPixel1 = new Pixel(backgroundDelete,x,y);

            targetPixel = backgroundImage.getPixel(x,y);                
            pixelColor = targetPixel.getColor();

            targetPixel1 = backgroundDelete.getPixel(x,y);
            pixelColor1 = targetPixel1.getColor();

            int targetRed = pixelColor1.getRed();
            int targetBlue = pixelColor1.getGreen();
            int targetGreen = pixelColor1.getBlue();

            int backgroundRed = pixelColor.getRed();
            int backgroundGreen = pixelColor.getGreen();
            int backgroundBlue = pixelColor.getBlue();

            if(targetRed >= 200 && targetBlue >= 200 && targetGreen >= 200) 
            {
                targetPixel1.setRed(backgroundRed);
                targetPixel1.setGreen(backgroundGreen);
                targetPixel1.setBlue(backgroundBlue);

            }
        }
    }
    backgroundImage.show();
    backgroundDelete.show();
}

}

【讨论】:

  • 是的,我确实已经导入了我需要的所有内容 [颜色/像素],在添加了您的建议后,我避免了编译器错误,并且程序给了我想要的结果!
猜你喜欢
  • 1970-01-01
  • 2011-04-23
  • 1970-01-01
  • 1970-01-01
  • 2013-01-03
  • 1970-01-01
  • 2015-11-06
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多