簡體   English   中英

android中的位圖圖像問題

[英]issue with bitmap image in android

我使用一些功能在我的android應用中顯示一些圖像。 從服務器讀取圖像,所有這些都很好。 但是我不知道為什么,我的應用程序顯示強制關閉,錯誤是:

嘗試在空對象引用上調用虛擬方法'int android.graphics.Bitmap.getWidth()'

這是錯誤從那里的代碼:

  Bitmap source = BitmapFactory.decodeFile(path);
    int size = Math.min(source.getWidth(), source.getHeight());
    int x = (source.getWidth() - size) / 2;
    int y = (source.getHeight() - size) / 2;

終於我用了默認圖像來解決我的問題。 我將其放在drawble文件夾中,並檢查是否未從服務器加載圖像,並且沒有顯示更多錯誤!

更新:

這是我使用這種方法的方式:

Bitmap source = BitmapFactory.decodeFile(path);
    if (source == null){
        source = BitmapFactory.decodeResource(MainActivity.getContext().getResources(), R.drawable.no_pic_feed);
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM