2014-03-18 61 views
0

我實際上想要一個textView來改變,當一組圖片匹配按鈕陣列的背景圖像。由於下面的代碼,我不知道爲什麼應用程序崩潰。 下面是代碼:比較按鈕圖像與可繪製圖像Android

protected void checkResult(int bx2[],int demon[]) { 
    // TODO Auto-generated method stub 
    final int[] cards1={R.drawable.one1,R.drawable.one2, 
      R.drawable.one3,R.drawable.two1,R.drawable.two2, 
      R.drawable.two3,R.drawable.three1, 
      R.drawable.three2,0}; 

    int klop=0; 
    for(int i=0; i<9;i++) { 
     int sene = cards1[i]; 
     Button vl = (Button) findViewById(bx2[i]); 
     if(vl.getBackground()==getResources().getDrawable(sene)) {  
       klop+=1; 
       if(klop==7) { 
        TextView tv = (TextView) findViewById(R.id.textView1); 
        tv.setText("PUZZLE SOLVED!"); 
       }  
     } 

    }   
}` 

回答

0

你的代碼,當你試圖獲得可繪製時i = 8sene = cards1[8] = 0;避免你可以添加一個簡單的檢查

int sene = cards1[i]; 
if (sene == 0) 
continue; 
+0

這有助於阻止CRASH崩潰將ResourceNotFoundException崩潰從再發生!謝謝! – wisejoy