Reputation: 2227
I am making an app in which i am getting an array of images from server. I need to display these images in my activity through dynamic array of imageviews and then ad these in linearlayout. i have used the folloeing code but getting null pointer exception.
URL myFileUrl =null;
myFileUrl= new URL(imageUrl);
int imageIndex = 0;
int n=stringOnTextView.length;
System.out.println(n);
for (int row = 0; row < Math.ceil(n/3); row++)
{
for (int column = 0; column < 3; column++)
{
myFileUrl= new URL(imageUrl);
HttpURLConnection conn= (HttpURLConnection)myFileUrl.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream is = conn.getInputStream();
bmImg = BitmapFactory.decodeStream(is);
System.out.println(images[imageIndex]);
images = new ImageView[n];
images[imageIndex].setImageBitmap(bmImg);
System.out.println("cccccc");
layoutImages.addView(images[imageIndex++],(column * 80)+20,(row * 80)+20);
Upvotes: 0
Views: 179
Reputation: 3882
Since you are not initializing arrat images[] that's why you r getting null pointer exception.
images = new ImageView[n]
change your code as shown above.
Upvotes: 2