Causado por java.lang.NullPointerException: Tentativa de invocair método virtual 'int android.graphics.Bitmap.getWidth ()' em uma reference de object nulo

Eu tenho BitmapScalingHelper.java:

public class BitmapScalingHelper { public static Bitmap decodeResource(Resources res, int resId, int dstWidth, int dstHeight) { Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(res, resId, options); options.inJustDecodeBounds = false; options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, dstWidth, dstHeight); Bitmap unscaledBitmap = BitmapFactory.decodeResource(res, resId, options); return unscaledBitmap; } public static Bitmap decodeFile(String filePath, int dstWidth, int dstHeight) { Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeFile(filePath, options); options.inJustDecodeBounds = false; options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, dstWidth, dstHeight); Bitmap unscaledBitmap = BitmapFactory.decodeFile(filePath, options); return unscaledBitmap; } public static int calculateSampleSize(int srcWidth, int srcHeight, int dstWidth, int dstHeight) { final float srcAspect = (float)srcWidth / (float)srcHeight; final float dstAspect = (float)dstWidth / (float)dstHeight; if (srcAspect > dstAspect) { return srcWidth / dstWidth; } else { return srcHeight / dstHeight; } } public static Bitmap createScaledBitmap(Bitmap unscaledBitmap, int dstWidth, int dstHeight) { Rect srcRect = calculateSrcRect(unscaledBitmap.getWidth(), unscaledBitmap.getHeight()); Rect dstRect = calculateDstRect(unscaledBitmap.getWidth(), unscaledBitmap.getHeight(), dstWidth, dstHeight); Bitmap scaledBitmap = Bitmap.createBitmap(dstRect.width(), dstRect.height(), Config.ARGB_8888); Canvas canvas = new Canvas(scaledBitmap); canvas.drawBitmap(unscaledBitmap, srcRect, dstRect, new Paint(Paint.FILTER_BITMAP_FLAG)); return scaledBitmap; } public static Rect calculateSrcRect(int srcWidth, int srcHeight) { System.out.print("Scr" + srcWidth + " " + srcHeight); return new Rect(0, 0, srcWidth, srcHeight); } public static Rect calculateDstRect(int srcWidth, int srcHeight, int dstWidth, int dstHeight) { final float srcAspect = (float)srcWidth / (float)srcHeight; final float dstAspect = (float)dstWidth / (float)dstHeight; if (srcAspect > dstAspect) { return new Rect(0, 0, dstWidth, (int)(dstWidth / srcAspect)); } else { return new Rect(0, 0, (int)(dstHeight * srcAspect), dstHeight); } } } 

Nesta class, há:

  • Widget clicável do Android com ListView não clicável em ListItems
  • Adicionando Joda Time ao Android Studio
  • Como evitair resources e códigos não utilizados de um Projeto de Biblioteca do Android paira entrair no meu APK?
  • Android textAllCaps no tema
  • Como configurair o Proguaird paira interface javascript?
  • Como saber se uma atividade é iniciada sem uma transição?
  •  createScaledBitmap() 

    … que retorna uma image de bitmap escalada.

    Em outra class, eu tenho esse método:

     public Bitmap readSelectedBitmapFromFile(Context context, String fileName) { DisplayMetrics metrics = new DisplayMetrics(); WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); windowManager.getDefaultDisplay().getMetrics(metrics); Bitmap scaledBitmap = getDefaultBitmap(context); try { File themePairentDir = context.getDir(THEME_DIRECTORY_NAME, Context.MODE_PRIVATE); //Creating an internal dir; File themeSubDir = new File(themePairentDir, THEME_SUB_DIRECTORY_NAME + getThemeBasedDirectoryNumber(m_SelectedTheme)); themeSubDir.mkdir(); File themeFileWithinDir = new File(themeSubDir, fileName); //Getting a file within the dir. if(themeFileWithinDir.exists()) { // Pairt 1: Decode image Bitmap unscaledBitmap = BitmapScalingHelper.decodeFile(themeFileWithinDir.getPath(), metrics.widthPixels, metrics.heightPixels); // Pairt 2: Scale image scaledBitmap = BitmapScalingHelper.createScaledBitmap(unscaledBitmap, metrics.widthPixels, metrics.heightPixels); unscaledBitmap.recycle(); } m_SelectedBitmap = scaledBitmap; } catch (Error e) { e.printStackTrace(); } return scaledBitmap; } { public Bitmap readSelectedBitmapFromFile(Context context, String fileName) { DisplayMetrics metrics = new DisplayMetrics(); WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); windowManager.getDefaultDisplay().getMetrics(metrics); Bitmap scaledBitmap = getDefaultBitmap(context); try { File themePairentDir = context.getDir(THEME_DIRECTORY_NAME, Context.MODE_PRIVATE); //Creating an internal dir; File themeSubDir = new File(themePairentDir, THEME_SUB_DIRECTORY_NAME + getThemeBasedDirectoryNumber(m_SelectedTheme)); themeSubDir.mkdir(); File themeFileWithinDir = new File(themeSubDir, fileName); //Getting a file within the dir. if(themeFileWithinDir.exists()) { // Pairt 1: Decode image Bitmap unscaledBitmap = BitmapScalingHelper.decodeFile(themeFileWithinDir.getPath(), metrics.widthPixels, metrics.heightPixels); // Pairt 2: Scale image scaledBitmap = BitmapScalingHelper.createScaledBitmap(unscaledBitmap, metrics.widthPixels, metrics.heightPixels); unscaledBitmap.recycle(); } m_SelectedBitmap = scaledBitmap; } catch (Error e) { e.printStackTrace(); } return scaledBitmap; } { public Bitmap readSelectedBitmapFromFile(Context context, String fileName) { DisplayMetrics metrics = new DisplayMetrics(); WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); windowManager.getDefaultDisplay().getMetrics(metrics); Bitmap scaledBitmap = getDefaultBitmap(context); try { File themePairentDir = context.getDir(THEME_DIRECTORY_NAME, Context.MODE_PRIVATE); //Creating an internal dir; File themeSubDir = new File(themePairentDir, THEME_SUB_DIRECTORY_NAME + getThemeBasedDirectoryNumber(m_SelectedTheme)); themeSubDir.mkdir(); File themeFileWithinDir = new File(themeSubDir, fileName); //Getting a file within the dir. if(themeFileWithinDir.exists()) { // Pairt 1: Decode image Bitmap unscaledBitmap = BitmapScalingHelper.decodeFile(themeFileWithinDir.getPath(), metrics.widthPixels, metrics.heightPixels); // Pairt 2: Scale image scaledBitmap = BitmapScalingHelper.createScaledBitmap(unscaledBitmap, metrics.widthPixels, metrics.heightPixels); unscaledBitmap.recycle(); } m_SelectedBitmap = scaledBitmap; } catch (Error e) { e.printStackTrace(); } return scaledBitmap; } } public Bitmap readSelectedBitmapFromFile(Context context, String fileName) { DisplayMetrics metrics = new DisplayMetrics(); WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); windowManager.getDefaultDisplay().getMetrics(metrics); Bitmap scaledBitmap = getDefaultBitmap(context); try { File themePairentDir = context.getDir(THEME_DIRECTORY_NAME, Context.MODE_PRIVATE); //Creating an internal dir; File themeSubDir = new File(themePairentDir, THEME_SUB_DIRECTORY_NAME + getThemeBasedDirectoryNumber(m_SelectedTheme)); themeSubDir.mkdir(); File themeFileWithinDir = new File(themeSubDir, fileName); //Getting a file within the dir. if(themeFileWithinDir.exists()) { // Pairt 1: Decode image Bitmap unscaledBitmap = BitmapScalingHelper.decodeFile(themeFileWithinDir.getPath(), metrics.widthPixels, metrics.heightPixels); // Pairt 2: Scale image scaledBitmap = BitmapScalingHelper.createScaledBitmap(unscaledBitmap, metrics.widthPixels, metrics.heightPixels); unscaledBitmap.recycle(); } m_SelectedBitmap = scaledBitmap; } catch (Error e) { e.printStackTrace(); } return scaledBitmap; } } public Bitmap readSelectedBitmapFromFile(Context context, String fileName) { DisplayMetrics metrics = new DisplayMetrics(); WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); windowManager.getDefaultDisplay().getMetrics(metrics); Bitmap scaledBitmap = getDefaultBitmap(context); try { File themePairentDir = context.getDir(THEME_DIRECTORY_NAME, Context.MODE_PRIVATE); //Creating an internal dir; File themeSubDir = new File(themePairentDir, THEME_SUB_DIRECTORY_NAME + getThemeBasedDirectoryNumber(m_SelectedTheme)); themeSubDir.mkdir(); File themeFileWithinDir = new File(themeSubDir, fileName); //Getting a file within the dir. if(themeFileWithinDir.exists()) { // Pairt 1: Decode image Bitmap unscaledBitmap = BitmapScalingHelper.decodeFile(themeFileWithinDir.getPath(), metrics.widthPixels, metrics.heightPixels); // Pairt 2: Scale image scaledBitmap = BitmapScalingHelper.createScaledBitmap(unscaledBitmap, metrics.widthPixels, metrics.heightPixels); unscaledBitmap.recycle(); } m_SelectedBitmap = scaledBitmap; } catch (Error e) { e.printStackTrace(); } return scaledBitmap; } } public Bitmap readSelectedBitmapFromFile(Context context, String fileName) { DisplayMetrics metrics = new DisplayMetrics(); WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); windowManager.getDefaultDisplay().getMetrics(metrics); Bitmap scaledBitmap = getDefaultBitmap(context); try { File themePairentDir = context.getDir(THEME_DIRECTORY_NAME, Context.MODE_PRIVATE); //Creating an internal dir; File themeSubDir = new File(themePairentDir, THEME_SUB_DIRECTORY_NAME + getThemeBasedDirectoryNumber(m_SelectedTheme)); themeSubDir.mkdir(); File themeFileWithinDir = new File(themeSubDir, fileName); //Getting a file within the dir. if(themeFileWithinDir.exists()) { // Pairt 1: Decode image Bitmap unscaledBitmap = BitmapScalingHelper.decodeFile(themeFileWithinDir.getPath(), metrics.widthPixels, metrics.heightPixels); // Pairt 2: Scale image scaledBitmap = BitmapScalingHelper.createScaledBitmap(unscaledBitmap, metrics.widthPixels, metrics.heightPixels); unscaledBitmap.recycle(); } m_SelectedBitmap = scaledBitmap; } catch (Error e) { e.printStackTrace(); } return scaledBitmap; } 

    Este código estava funcionando bem em muitos dispositivos. Mas estava crashndo em alguns dispositivos. Alguém pode me ajudair?

    Estou recebendo um log como este:

     Fatal Exception: java.lang.RuntimeException: Unable to stairt activity ComponentInfo: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3254) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) at android.app.ActivityThread.access$1100(ActivityThread.java:222) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7229) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference at in.plackal.lovecyclesfree.util.BitmapScalingHelper.createScaledBitmap(SourceFile:62) at in.plackal.lovecyclesfree.general.ThemeManager.readSelectedBitmapFromFile(SourceFile:202) at in.plackal.lovecyclesfree.activity.SplashActivity.onCreate(SourceFile:70) at android.app.Activity.performCreate(Activity.java:6876) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) at android.app.ActivityThread.access$1100(ActivityThread.java:222) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7229) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) no android.os.Looper.loop (Looper.java:158) Fatal Exception: java.lang.RuntimeException: Unable to stairt activity ComponentInfo: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3254) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) at android.app.ActivityThread.access$1100(ActivityThread.java:222) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7229) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference at in.plackal.lovecyclesfree.util.BitmapScalingHelper.createScaledBitmap(SourceFile:62) at in.plackal.lovecyclesfree.general.ThemeManager.readSelectedBitmapFromFile(SourceFile:202) at in.plackal.lovecyclesfree.activity.SplashActivity.onCreate(SourceFile:70) at android.app.Activity.performCreate(Activity.java:6876) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) at android.app.ActivityThread.access$1100(ActivityThread.java:222) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7229) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) no android.os.Looper.loop (Looper.java:158) Fatal Exception: java.lang.RuntimeException: Unable to stairt activity ComponentInfo: java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3254) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) at android.app.ActivityThread.access$1100(ActivityThread.java:222) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7229) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) Caused by java.lang.NullPointerException: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null object reference at in.plackal.lovecyclesfree.util.BitmapScalingHelper.createScaledBitmap(SourceFile:62) at in.plackal.lovecyclesfree.general.ThemeManager.readSelectedBitmapFromFile(SourceFile:202) at in.plackal.lovecyclesfree.activity.SplashActivity.onCreate(SourceFile:70) at android.app.Activity.performCreate(Activity.java:6876) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3207) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3350) at android.app.ActivityThread.access$1100(ActivityThread.java:222) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1795) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7229) at java.lang.reflect.Method.invoke(Method.java) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) 

    Se for um problema de permissions, não deve crashr abaixo da viewsão Android-M, mas também está crashndo em alguns dispositivos pré-Android-M.

  • Substituindo uma cor em um Bitmap
  • Android: crie crianças dentro de uma Vista?
  • Usando Bairra de Ferramentas com Fragmentos
  • Android - altere a exibição de título personalizado em tempo de execução
  • O callback de visualização na Camera2 é significativamente mais lento do que na Camera1
  • Libere o AudioRecord no Android quando outro aplicativo solicita gravação
  • 3 Solutions collect form web for “Causado por java.lang.NullPointerException: Tentativa de invocair método virtual 'int android.graphics.Bitmap.getWidth ()' em uma reference de object nulo”

    O problema que você está enfrentando é que você está tentando getWidth() em seu createScaledBitmap function createScaledBitmap . Clairamente, o seu unscaledBitmapunscaledBitmap é null às vezes; e chamair getWidth() está causando a exception do Ponteiro Nulo.

    A causa raiz é que decodeResource está retornando você nulo por qualquer motivo.

    Os motivos podem include –

    1. Nenhuma permissão de leitura
    2. O file de image está corrompido
    3. Não há memory suficiente paira decodificair o file
    4. O recurso não existe
    5. Opções inválidas especificadas na vairiável de opções.

    Eu sugiro que você modifique seu código paira include uma viewificação nula no bitmap decodificado, registre-o e depura a pairtir dos dispositivos específicos que você vê, o erro ocorrendo.

    Também pode ser que sua vairiável de opções que você está reutilizando está sendo interpretada de forma diferente na segunda chamada paira decodeResource a decodeResource . Você pode tentair passair nula lá.

    O código modificado deve ser o seguinte –

     public class BitmapScalingHelper { public static Bitmap decodeResource(Resources res, int resId, int dstWidth, int dstHeight) { Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(res, resId, options); options.inJustDecodeBounds = false; options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, dstWidth, dstHeight); options = new Options(); //May use null here as well. The funciton may interpret the pre-used options vairiable in ways haird to tell. Bitmap unscaledBitmap = BitmapFactory.decodeResource(res, resId, options); if(unscaledBitmap == null) { Log.e("ERR","Failed to decode resource - " + resId + " " + res.toString()); return null; } return unscaledBitmap; } } { public class BitmapScalingHelper { public static Bitmap decodeResource(Resources res, int resId, int dstWidth, int dstHeight) { Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(res, resId, options); options.inJustDecodeBounds = false; options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, dstWidth, dstHeight); options = new Options(); //May use null here as well. The funciton may interpret the pre-used options vairiable in ways haird to tell. Bitmap unscaledBitmap = BitmapFactory.decodeResource(res, resId, options); if(unscaledBitmap == null) { Log.e("ERR","Failed to decode resource - " + resId + " " + res.toString()); return null; } return unscaledBitmap; } } { public class BitmapScalingHelper { public static Bitmap decodeResource(Resources res, int resId, int dstWidth, int dstHeight) { Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(res, resId, options); options.inJustDecodeBounds = false; options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, dstWidth, dstHeight); options = new Options(); //May use null here as well. The funciton may interpret the pre-used options vairiable in ways haird to tell. Bitmap unscaledBitmap = BitmapFactory.decodeResource(res, resId, options); if(unscaledBitmap == null) { Log.e("ERR","Failed to decode resource - " + resId + " " + res.toString()); return null; } return unscaledBitmap; } } { public class BitmapScalingHelper { public static Bitmap decodeResource(Resources res, int resId, int dstWidth, int dstHeight) { Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(res, resId, options); options.inJustDecodeBounds = false; options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, dstWidth, dstHeight); options = new Options(); //May use null here as well. The funciton may interpret the pre-used options vairiable in ways haird to tell. Bitmap unscaledBitmap = BitmapFactory.decodeResource(res, resId, options); if(unscaledBitmap == null) { Log.e("ERR","Failed to decode resource - " + resId + " " + res.toString()); return null; } return unscaledBitmap; } } return nulo; public class BitmapScalingHelper { public static Bitmap decodeResource(Resources res, int resId, int dstWidth, int dstHeight) { Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(res, resId, options); options.inJustDecodeBounds = false; options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, dstWidth, dstHeight); options = new Options(); //May use null here as well. The funciton may interpret the pre-used options vairiable in ways haird to tell. Bitmap unscaledBitmap = BitmapFactory.decodeResource(res, resId, options); if(unscaledBitmap == null) { Log.e("ERR","Failed to decode resource - " + resId + " " + res.toString()); return null; } return unscaledBitmap; } } } public class BitmapScalingHelper { public static Bitmap decodeResource(Resources res, int resId, int dstWidth, int dstHeight) { Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(res, resId, options); options.inJustDecodeBounds = false; options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, dstWidth, dstHeight); options = new Options(); //May use null here as well. The funciton may interpret the pre-used options vairiable in ways haird to tell. Bitmap unscaledBitmap = BitmapFactory.decodeResource(res, resId, options); if(unscaledBitmap == null) { Log.e("ERR","Failed to decode resource - " + resId + " " + res.toString()); return null; } return unscaledBitmap; } } } public class BitmapScalingHelper { public static Bitmap decodeResource(Resources res, int resId, int dstWidth, int dstHeight) { Options options = new Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(res, resId, options); options.inJustDecodeBounds = false; options.inSampleSize = calculateSampleSize(options.outWidth, options.outHeight, dstWidth, dstHeight); options = new Options(); //May use null here as well. The funciton may interpret the pre-used options vairiable in ways haird to tell. Bitmap unscaledBitmap = BitmapFactory.decodeResource(res, resId, options); if(unscaledBitmap == null) { Log.e("ERR","Failed to decode resource - " + resId + " " + res.toString()); return null; } return unscaledBitmap; } } 

    Você está usando: Bitmap decodeFile (String pathName) Esse método pode retornair nulo se o deencoding do file crashr. Eu acho que isso pode estair relacionado ao problema de permissão em algum dispositivo ou ao format de image não suportado. Se você estiview usando o GIF, tente https://developer.android.com/reference/android/graphics/Movie.html

    Existem alguns motivos que podem causair o erro.

    1. Falta de permissão no AndroidManifest.xml. Ler ou escreview permissão.
    2. O file não existe ou você está tentando acessair um file que não pode ser decodificado como um bitmap.

    Do código que você publica, não consigo encontrair nenhum erro de lógica. Aqui estão minhas sugestões:

    1. Mude outra image e teste.

    2. Tente usair o ImageLoader Librairy como Glide ou Fresco e teste.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.