2012-11-28 6 views
0

음,이 메서드는 특정 비율로 호출 된 Object2D의 2 차원 색상 배열 PointInformation의 크기를 조정해야하는 클래스 Object2D에서 크기 조정을 수행했습니다.이상하게 도달 할 수 없지만 컴파일 할 수 있습니다. 코드

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!?  
} 
} 

그것은 기본적으로 온도 [0]에서 시작하여 한이 같은 색을 찾아로 INT의 SamePixelCount 1 추가 (I는 1 차원 배열로 2D-배열을 convertig 때 쉽게이해야 할 것을 발견). 다른 Color가 발견되면이 메서드는 이전 Pixel의 Color를 temp2 Array의 오른쪽 Places에 씁니다. 내가 테스트하고 싶었 기 때문에

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; 
    } 
} 

개체의 PointInformation로 조작 배열 TEMP2의 올바른 번역은 여전히 ​​누락, TEMP2가 올바르게 온도에서 크기가 조정 된 경우, 그래서 나는

Standart_Methods.PrintArray(temp2); //the Method works btw 

을했다지만 그냥 아무것도하지 않았다! 그리고 심지어 더 나쁜! 내가 그 명령의 장소에 두는 모든 것은 또한하지 않았다!

int a = 10; 
    int b = 0; 
    System.out.print(a/b); //No Exeption! 

그리고 무엇 심지어 낯선 사람, 최대한 빨리 전화로 방법 크기 조정는, 어딘가에, 통화 후 모든 것이 같은 이상한 도달 할 수없는 코드로 켜지는지!?

나는이 문제를 일으킬 수있는 것에 대해 진지하게 모릅니다.

도움이 될 것입니다.

+1

예외적으로 호출 체인에서 더 높은 값을 얻을 수 있습니까? –

+0

그러면 적어도 Standart_Methods.PrintArray (temp2)를 수행합니다. 그렇지 않니? –

+0

그렇다면 'System.out.print (a/b);'는 실행 흐름을 깨고 예외를 던질 것입니다. 만약 누군가가'try {myObject2D.Resize (10)} catch (Exception e) {/ * 아무것도 * /}'와 같은 것을했다면 예외가 보이지 않을 것입니다. –

답변

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) 

내가 사용 일식을 제안하고 디버거를 사용하여 코드를 추적. 코드 라인 당 변수를 검사하면 무엇이 잘못되었는지 파악할 수 있습니다.

+0

아하, 당신이 추천하는 경우에도 맞습니다. int 대신 double을 사용하면 예외가 발생하지 않습니다. (Double.Infinity가 결과 임) – AlexWien

+1

예. 당신의 예에서 그것은 당신에게 그런 종류의 예외를줍니다; 그러나 문맥 상 그 코드는 나의 예일뿐입니다. 나는이 코드에 도달하지 않았다는 것을 보여주는 10/0 코드를 넣었습니다. 실제로이 진술이있는 모든 장소에 도달 할 수 없습니다! 그것은 전혀 유용하지 않았습니다, 미안 해요. –

관련 문제