【问题标题】:The operator * is undefined for the argument types [][]array, double运算符 * 未定义参数类型 [][]array, double
【发布时间】:2012-09-20 01:05:43
【问题描述】:

我正在做一个对图像进行简单对比的项目,我已经扫描了数组以找到最小值和最大值,但现在我必须绘制图像。

我不断收到此错误“操作符 * 未定义参数类型绘图面板,双精度”

这里是代码

    public void simple (Graphics g) {
    if (DrawingPanel.imageArray != null) {
        int width = getWidth();
        int height = getHeight();
        int hPos = (width - DrawingPanel.imageArray[0].length) / 2;
        int vPos = (height - DrawingPanel.imageArray.length) / 2;
        for (int r = 0; r < DrawingPanel.imageArray.length; r++)
            for (int c = 0; c < DrawingPanel.imageArray[r].length; c++) {
                newc = Math.round(maxshade * ((double)(DrawingPanel.imageArray[r][c] - minshade) / (maxedshade - minshade))); //error here!!!
                g.setColor(new Color(DrawingPanel.imageArray[r][c], DrawingPanel.imageArray[r][c], DrawingPanel.imageArray[r][c]));
                g.drawLine(c+hPos, r+vPos, c+hPos, r+vPos);                     
            }
        g.setColor(Color.black);
        g.drawRect(hPos, vPos, DrawingPanel.imageArray[0].length, DrawingPanel.imageArray.length);                  
}

}

任何帮助将不胜感激..谢谢!

这也是我计算最小最大值的地方...

    public static void computeImageStatistics(DrawingPanel array) {
        DrawingPanel.array = carray;
            maxedshade = carray[0][0];      
            for (int i = 0; i < carray.length; i++) {
              for (int j = 0; j < carray[i].length; j++) {
                if (carray[i][j] > maxedshade) {
                  maxedshade = carray[i][j];
                }
              }
            }
            minshade = carray[0][0];    
            for (int i = 0; i < carray.length; i++) {
              for (int j = 0; j < carray[i].length; j++) {
                if (minshade > carray[i][j]) {
                    minshade = carray[i][j];
                }
    }
            }
    }

以及我的绘图面板中的一些其他变量..

     public void showImage(File fileName) {
        Scanner scan;
        try {
            scan = new Scanner(fileName);
            typefile = scan.next();
            iname = scan.next();       
            width = scan.nextInt();
            height = scan.nextInt();
            maxshade = scan.nextInt();
            array = new int[width][height];

            for(int r = 0; r < array.length; r++)
                for(int c = 0; c < array[r].length; c++)
                    array[r][c] = scan.nextInt();
            imageArray = array;
            repaint();              
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

 }

【问题讨论】:

标签: java arrays error-handling project


【解决方案1】:

错误消息告诉您不能在maxshade((double)(DrawingPanel.imageArray[r][c] - minshade) / (maxedshade - minshade)) 之间使用运算符'*'。因为 maxshade 是 DrawingPanel 的类型,而不是数字(double/long/float/int...)。

当我查看您的第二个代码块时,我看到一个静态变量名称 maxedshade 。它看起来像一个数字。

然后我查看您的错误行:

newc = Math.round(maxshade * ((double)(DrawingPanel.imageArray[r][c] - minshade) / (maxedshade - minshade))); //error here!!!

您是否在“ma​​xshade”上输入错误?应该是 ma​​xedshade 吗?

【讨论】:

    猜你喜欢
    • 2016-01-26
    • 2021-07-03
    • 1970-01-01
    • 2015-12-14
    • 1970-01-01
    • 2012-03-03
    • 2014-06-02
    • 2021-01-29
    • 1970-01-01
    相关资源
    最近更新 更多