从Bitmap在imageView中设置Image时出现NullPointerException?

时间:2012-05-25 05:59:17

标签: android xml nullpointerexception expansion

我正在使用http://developer.android.com/guide/market/expansion-files.html

中的APK扩展文件

代码:

String[] path= getAPKExpansionFiles(this,2,0);
ZipResourceFile expansionFile;
try {
        expansionFile = new ZipResourceFile(path[0]);
        InputStream fileStream = expansionFile.getInputStream("assets/Tablet/Chester_the_cat/chester_the_cat_2.png");
        Bitmap bit=BitmapFactory.decodeStream(fileStream);
            iv_new=(ImageView)findViewById(R.id.iv_new);
            iv_new.setImageBitmap(bit);

并在此行中获得此NullPointerException

   iv_new.setImageBitmap(bit);

在XML中,我的ImageView是:

 <ImageView android:id="@+id/iv_new"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"/>

1 个答案:

答案 0 :(得分:2)

您是否使用包含ImageView的布局调用setContentView(View)