balaji
balaji

Reputation: 1575

how to add imageview in view array?

I have created View[] regionView; variable and I am trying to add ImageView in this regionView array but I getting null pointer exception. Please help me how to add imageview in this View

ViewInfo.class

public class ViewInfo {
    View[] regionView;
}

everytime i wish to add imageview values in this regionView array: so I have applied code in this below.

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);

        }

above code I am trying to imageview in this array but I am getting null pointer exception:

error line:

ViewInfo.regionView[a] =img;

Upvotes: 0

Views: 185

Answers (1)

CRUSADER
CRUSADER

Reputation: 5472

I dont think there is issue img object but ViewInfo.regionView may not have been initialised, hence it shows null pointer exception. Please initialise this view array with some size. i.e

View[] regionView = new View[some size];

Upvotes: 1

Related Questions