Dynamic layout error
i have display image from url.that i smy code.it show me nullpointer exception warning and my screen seen blank.
try {
for(i=0;i<4;i++)
{
url[i] = new URL(str[i]);
Log.v("....urllength....",url[i]+"");
tr.setLayoutParams(new LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
conn[i]=(HttpURLConnection)url[i].openConnection();
conn[i].setDoInput(true);
conn[i].connect开发者_Python百科();
is[i] = conn[i].getInputStream();
//Log.v("....is....",is[i]+"");
bmp[i] = BitmapFactory.decodeStream(is[i]);
iv.setImageBitmap(bmp[i]);
iv.setLayoutParams(new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
tr.addView(iv);
tl.addView(tr,new TableLayout.LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
}
}
I think you are missing one of the following variable to be initialized.
- tr
- tl
- iv
- str[]
Cheers..
The exception should say on what line the nullpointerexception occurred, and you can work back from that to the source of the exception. As Android_Crazy said, it probably is an uninitialized variable.
精彩评论