2014-02-23 4 views
0

나는이 방법은 이미지 리소스를 설정하기위한 올바른 보이나요 .... 드로어 블의 배열에서 프로그래밍 방식으로 이미지 뷰의 이미지를 설정하지만, NullPointerException가 점점 계속 노력하고 있어요 ..설정 이미지 뷰 그리기 programmically

//get a random drawable 
int[] imageSelection= {R.drawable.buddycheck, R.drawable.logdive3, R.drawable.sea, R.drawable.weather, R.drawable.logo1}; 
Random whichImage = new Random(); 
int theImage = whichImage.nextInt(imageSelection.length); 

displayImage.setBackgroundResource(theImage); 
+1

displayImage를 어디에서 어떻게 초기화합니까? – BrainCrash

답변

3

이미지 리소스를 임의의 숫자로 설정합니다. 다음과 같이해야합니다.

int theImage = imageSelection[whichImage.nextInt(imageSelection.length)]; 
displayImage.setBackgroundResource(theImage); 
+0

완벽, 건배 – dancingbush

+0

행운 남자의 최고 :) –