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

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -