开发者

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.

  1. tr
  2. tl
  3. iv
  4. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜