0
我已經創建了View [] regionView;變量,我想在這個regionView數組中添加ImageView,但我得到空指針異常。請幫助我如何在此查看如何在view數組中添加imageview?
ViewInfo.class
public class ViewInfo {
View[] regionView;
}
每次我希望在這個regionView陣列添加imageview的添加值的ImageView:所以我在此下方施加代碼。
main.class
if(RegionOptions.type.compareTo(Image)==0){
String is = null;
is = Environment.getExternalStorageDirectory()+"/xibo/"+RegionOptions.uri;
Bitmap image = BitmapFactory.decodeFile(is);
img = new ImageView(mcontext);
RelativeLayout.LayoutParams vp =
new RelativeLayout.LayoutParams((width*RegionOptions.width)/lay_width,
(height*RegionOptions.height)/lay_height);
vp.setMargins((width*RegionOptions.left)/lay_width,(height*RegionOptions.top)/lay_height, 0, 0);
img.setLayoutParams(vp);
img.setImageBitmap(image);
//adding image_values in array
try{
ViewInfo.regionView[a] =img;
}catch(Exception e){
e.printStackTrace();
}
// if(regionInfo.Region_views[a]!=null){
// layout.removeView(img);
// }
layout.addView(img);
}
上面的代碼我試圖imageview的本陣,但我得到空指針異常:
錯誤行:
ViewInfo.regionView[a] =img;