android - how to add imageview in view array? -
i have created view[] regionview; variable , trying add imageview in regionview array getting null pointer exception. please me how add imageview in view
viewinfo.class
public class viewinfo { view[] regionview; } everytime wish add imageview values in regionview array: have applied code in below.
main.class
if(regionoptions.type.compareto(image)==0){ string = null; = 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); } above code trying imageview in array getting null pointer exception:
error line:
viewinfo.regionview[a] =img;
i dont think there issue img object viewinfo.regionview may not have been initialised, hence shows null pointer exception. please initialise view array size. i.e
view[] regionview = new view[some size];
Comments
Post a Comment