Java tutorial
//package com.java2s; import android.graphics.Bitmap; import android.graphics.drawable.BitmapDrawable; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; public class Main { private static void setBitmap(BitmapDrawable drawable, Bitmap bitmap) { try { Method method = getMethod(BitmapDrawable.class, "setBitmap", new Class[] { Bitmap.class }); if (method != null) { method.setAccessible(true); method.invoke(drawable, bitmap); } } catch (NoSuchMethodException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InvocationTargetException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } @SuppressWarnings({ "unchecked", "rawtypes" }) private static Method getMethod(Class clazz, String methodName, final Class[] classes) throws Exception { Method method = null; try { method = clazz.getDeclaredMethod(methodName, classes); } catch (NoSuchMethodException e) { try { method = clazz.getMethod(methodName, classes); } catch (NoSuchMethodException ex) { if (clazz.getSuperclass() == null) { return method; } else { method = getMethod(clazz.getSuperclass(), methodName, classes); } } } return method; } }