繁体   English   中英

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

[英]NullPointerException while setting Image in imageView from Bitmap?

我正在使用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"/>

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM