嗯,我在我的Class Object2D中调整了这个方法,它应该调整Object2D的二维Color-Array PointInformation,它被调用到某个百分比。 (我发现将2D阵列转换为一维阵列时更容易做到)
public class Object2D
{
int width;
int height;
int ResizePercentage = 100;
Color PointInformation[][];
public void Resize(int Percentage)
{
Color[]temp = Standart_Methods.Reduce2DArray(this.PointInformation);
int temp_width = this.width;
int temp_height = this.height;
double Faktor = (Percentage+100)/100;
this.width = (int) (this.width*Faktor);
this.height = (int) (this.height*Faktor);
this.ResetPointInformation();
Color[]temp2 = Standart_Methods.Reduce2DArray(this.PointInformation);
int SamePixelCount = 0;
Color LastColor = temp[0];
for (int i = 0; i < temp.length; i++)
{
if (temp[i] == LastColor )
{
SamePixelCount += 1;
}
else
{
for (int i2 = (int) (i*Faktor); i == 1; i-- )
//Method Resize will only be called when i*Faktor is going to be 100% = X.0 (An Integer)
{
temp2[i*2-i] = LastColor;
}
SamePixelCount = 0;
}
}
Standart_Methods.PrintArray(temp2);
int a = 10;
int b = 0;
System.out.print(a/b); //No Exeption, Code unreachable!?
}
}
它基本上从temp [0]开始,只要找到相同的Color,就会向int SamePixelCount添加1。 找到不同的颜色后,该方法会将前一个像素的颜色写入temp2数组中的右侧位置。
for (int i = 0; i < temp.length; i++)
{
if (temp[i] == LastColor )
{
SamePixelCount += 1;
}
else
{
for (int i2 = (int) (i*Faktor); i == 1; i-- )
//Method Resize will only be called when i*Faktor is going to be 100% = X.0 (An Integer)
{
temp2[i*2-i] = LastColor;
}
SamePixelCount = 0;
}
}
操作数组temp2到Object的PointInformation的正确转换仍然缺失,因为我想测试一下,如果temp2正确调整了temp的大小,那么我做了
Standart_Methods.PrintArray(temp2); //the Method works btw
但它什么也没做!甚至是bader!我放在那个命令所在的一切,也没有!
int a = 10;
int b = 0;
System.out.print(a/b); //No Exeption!
更奇怪的是,只要我在某个地方调用方法调整大小,呼叫之后的所有内容都会变成同样奇怪的无法访问的代码!?
我对可能导致这个问题的原因完全不了解。
任何帮助都会很棒!
答案 0 :(得分:0)
除以零肯定会给你ArithmeticException:
public class Test {
public static void main(String[] args) {
int a = 10;
int b = 0;
System.out.println(a/b);
}
}
Exception in thread "main" java.lang.ArithmeticException: / by zero
at Test.main(Test.java:14)
我建议使用eclipse并使用调试器跟踪代码。检查每个代码行的变量,我相信你可以找出我们的错误