【发布时间】:2014-01-23 18:38:03
【问题描述】:
我的代码遇到了一些问题。我将用粗体突出显示错误(星号**):) 提前致谢 (突出显示的代码有这个错误:x 无法解析为变量”)
package com.cmnatic.reborn.gui;
public class Bitmap {
public final int width;
public final int height;
public final int[] pixels;
public Bitmap(int width, int height) {
this.width = width;
this.height = height;
pixels = new int[width * height];
}
public void draw(Bitmap bitmap, int xOffs, int yOffs) {
for (int y = 0; y<bitmap.height; y++) {
int yPix = y+yOffs;
if (yPix<0 || yPix>=height) continue;
for(int xPix = 0; **x**<bitmap.width; x++) {
int **xPix** = **x+x0ffs**;
if (xPix<0 || xPix>=width) continue;
pixels[xPix+yPix*width] = bitmap.pixels[x + y * bitmap.width];
}
}
}
}
另外,我有一个奇怪的问题,我不确定: (下面突出显示的代码有以下错误:“Duplicate local variable xPix”
for(int xPix = 0; **x**<bitmap.width; x++) {
int **xPix** = **x+x0ffs**;
if (xPix<0 || xPix>=width) continue;
提前致谢, CMNatic
【问题讨论】:
-
xPix 和 x 是两个不同的变量。
-
对这条消息的直接反应应该是:“为什么?我已经定义了它,等等,……嗯,那是什么……哦,我的天哪,愚蠢的我”。这比在 SO 上询问要快得多。
标签: java variables int pixel pixels