Note that there are some explanatory texts on larger screens.

plurals
  1. PONull Pointer Exception in combining two Bitmap Images
    primarykey
    data
    text
    <p>I am using a method to <code>combine two Bitmap Images</code> and write in the <code>SDCard</code>. The App. works fine in the emulator, but when I tried to execute in on the Real Device it throughs <code>Null Pointer Exception</code> at this line <code>cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);</code> that is to create a <code>new Bitmap</code> on which I will draw both the images that are to be combined using <code>Canvas</code>. </p> <p>Now, here in <code>combineImages(Bitmap background, Bitmap foreground)</code> the first argument is the <code>Bitmap from Camera</code> Picture and the <code>second is the forefround Gallery item</code>. The Bitmap taken from Camera is a <code>static Bitmap</code>, I guess that is the only thing that is running me into trouble. So, could someone give me a nice solution to save a picture taken from <code>Camera</code> as a <code>temporary</code> storage so that I doesn't make any issue which using it further.</p> <pre><code>public void combineImages(Bitmap background, Bitmap foreground) { Bitmap cs = null; int width = 0, height = 0; width = background.getWidth(); height = background.getHeight(); cs = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas comboImage = new Canvas(cs); comboImage.drawBitmap(background, 0, 0, null); comboImage.drawBitmap(foreground, 100, 300, null); String tmpImg = String.valueOf(System.currentTimeMillis()) + ".png"; OutputStream os = null; try { os = new FileOutputStream(Environment.getExternalStorageDirectory() + File.separator + tmpImg); cs.compress(CompressFormat.PNG, 100, os); } catch (IOException e) { e.printStackTrace(); } } </code></pre> <p>Here is my Logcat Output when I tried on Real Device.(LG Optimus Black P-970)</p> <pre><code>10-04 12:36:08.329: ERROR/AndroidRuntime(16356): FATAL EXCEPTION: main 10-04 12:36:08.329: ERROR/AndroidRuntime(16356): java.lang.NullPointerException 10-04 12:36:08.329: ERROR/AndroidRuntime(16356): at android.graphics.Bitmap.createBitmap(Bitmap.java:469) 10-04 12:36:08.329: ERROR/AndroidRuntime(16356): at com.cam.GalleryImageSelected.combineImages(GalleryImageSelected.java:66) 10-04 12:36:08.329: ERROR/AndroidRuntime(16356): at com.cam.GalleryImageSelected$1.onClick(GalleryImageSelected.java:90) 10-04 12:36:08.329: ERROR/AndroidRuntime(16356): at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:874) 10-04 12:36:08.329: ERROR/AndroidRuntime(16356): at android.widget.AdapterView.performItemClick(AdapterView.java:294) 10-04 12:36:08.329: ERROR/AndroidRuntime(16356): at android.widget.ListView.performItemClick(ListView.java:3387) 10-04 12:36:08.329: ERROR/AndroidRuntime(16356): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2408) 10-04 12:36:08.329: ERROR/AndroidRuntime(16356): at android.os.Handler.handleCallback(Handler.java:587) 10-04 12:36:08.329: ERROR/AndroidRuntime(16356): at android.os.Handler.dispatchMessage(Handler.java:92) 10-04 12:36:08.329: ERROR/AndroidRuntime(16356): at android.os.Looper.loop(Looper.java:123) 10-04 12:36:08.329: ERROR/AndroidRuntime(16356): at android.app.ActivityThread.main(ActivityThread.java:4627) 10-04 12:36:08.329: ERROR/AndroidRuntime(16356): at java.lang.reflect.Method.invokeNative(Native Method) 10-04 12:36:08.329: ERROR/AndroidRuntime(16356): at java.lang.reflect.Method.invoke(Method.java:521) 10-04 12:36:08.329: ERROR/AndroidRuntime(16356): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:876) 10-04 12:36:08.329: ERROR/AndroidRuntime(16356): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:634) 10-04 12:36:08.329: ERROR/AndroidRuntime(16356): at dalvik.system.NativeStart.main(Native Method) </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload