我試圖從可繪製的陣列編程方式設置的ImageView的形象,而且不斷得到一個NullPointerException ....確實這個方法查找設置圖像資源的正確..設置ImageView的繪製對象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);
你在哪裏以及如何初始化displayImage? – BrainCrash