簡體   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