My code runs without any errors on ICS but in Froyo it gives me a runtime NullPointerException
on the Bitmap.createBitmap()
call (line 7 in code below.) What can be causing it?
BitmapDrawable bd = (BitmapDrawable) getResources().getDrawable(R.drawable.title_bg_tile);
int width = view.getWidth();
int intrinsicHeight = bd.getIntrinsicHeight();
Rect bounds = new Rect(0,0,width,intrinsicHeight);
bd.setTileModeX(TileMode.REPEAT);
bd.setBounds(bounds);
Bitmap bitmap=Bitmap.createBitmap(bounds.width(),bounds.height(),bd.getBitmap().getConfig()); //<----Error on this line
Canvas canvas = new Canvas(bitmap);
bd.draw(canvas);
EDIT: My Logcat during crash on Froyo:
06-23 10:50:14.900: E/AndroidRuntime(276): FATAL EXCEPTION: main
06-23 10:50:14.900: E/AndroidRuntime(276): java.lang.NullPointerException
06-23 10:50:14.900: E/AndroidRuntime(276): at android.graphics.Bitmap.createBitmap(Bitmap.java:468)
06-23 10:50:14.900: E/AndroidRuntime(276): at com.tab.fragment.TabsViewPagerFragmentActivity$1.onGlobalLayout(TabsViewPagerFragmentActivity.java:95)
06-23 10:50:14.900: E/AndroidRuntime(276): at android.view.ViewTreeObserver.dispatchOnGlobalLayout(ViewTreeObserver.java:549)
06-23 10:50:14.900: E/AndroidRuntime(276): at android.view.ViewRoot.performTraversals(ViewRoot.java:1094)
06-23 10:50:14.900: E/AndroidRuntime(276): at android.view.ViewRoot.handleMessage(ViewRoot.java:1727)
06-23 10:50:14.900: E/AndroidRuntime(276): at android.os.Handler.dispatchMessage(Handler.java:99)
06-23 10:50:14.900: E/AndroidRuntime(276): at android.os.Looper.loop(Looper.java:123)
06-23 10:50:14.900: E/AndroidRuntime(276): at android.app.ActivityThread.main(ActivityThread.java:4627)
06-23 10:50:14.900: E/AndroidRuntime(276): at java.lang.reflect.Method.invokeNative(Native Method)
06-23 10:50:14.900: E/AndroidRuntime(276): at java.lang.reflect.Method.invoke(Method.java:521)
06-23 10:50:14.900: E/AndroidRuntime(276): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
06-23 10:50:14.900: E/AndroidRuntime(276): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
06-23 10:50:14.900: E/AndroidRuntime(276): at dalvik.system.NativeStart.main(Native Method)