Note that there are some explanatory texts on larger screens.

plurals
  1. POException while Loading Image from gallery
    text
    copied!<p>I am developing a Finger painting application. I have following code for loading an image from gallery (to paint over it). The code is working fine in my smartphone (android 4.2.2 - API 17). but when i run it on lower versions (2.3.3 etc), It just shows a run time error and app is closed.</p> <pre><code> protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_CODE &amp;&amp; resultCode == Activity.RESULT_OK) try { // We need to recyle unused bitmaps if (bitmap != null) { bitmap.recycle(); } InputStream stream = getContentResolver().openInputStream( data.getData()); myBitmap = BitmapFactory.decodeStream(stream); stream.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } </code></pre> <p>and for calling this</p> <pre><code>Intent intent = new Intent(); intent.setType("image/*"); intent.setAction(Intent.ACTION_GET_CONTENT); intent.addCategory(Intent.CATEGORY_OPENABLE); startActivityForResult(intent, REQUEST_CODE); </code></pre> <p>In my understanding, this code should work for all the APIs. But there is some problem with lower versions. please help me out</p> <p>EDIT:</p> <p>(I have deleted DISPLAY code, that was causing problem. still the problem persists. here is new logcat. LOGCAT after clicking LOAD button</p> <pre><code>08-25 18:55:51.079: D/ActionBarSherlock(524): [callbackOptionsItemSelected] item: Load 08-25 18:55:51.089: D/ActionBarSherlock(524): [callbackOptionsItemSelected] returning true 08-25 18:55:51.141: D/PhoneWindow(524): couldn't save which view has focus because the focused view com.example.colordraw.CanvasActivity$Canvass@4050a590 has no id. 08-25 18:55:51.159: D/ActionBarSherlock(524): [dispatchPause] 08-25 18:55:51.899: D/ActionBarSherlock(524): [dispatchStop] 08-25 18:55:53.259: D/ActionBarSherlock(524): [dispatchPostResume] 08-25 18:55:53.379: D/AndroidRuntime(524): Shutting down VM 08-25 18:55:53.379: W/dalvikvm(524): threadid=1: thread exiting with uncaught exception (group=0x40015560) 08-25 18:55:53.400: E/AndroidRuntime(524): FATAL EXCEPTION: main 08-25 18:55:53.400: E/AndroidRuntime(524): java.lang.IllegalStateException: Immutable bitmap passed to Canvas constructor 08-25 18:55:53.400: E/AndroidRuntime(524): at android.graphics.Canvas.&lt;init&gt;(Canvas.java:83) 08-25 18:55:53.400: E/AndroidRuntime(524): at com.example.colordraw.CanvasActivity$Canvass.onDraw(CanvasActivity.java:780) 08-25 18:55:53.400: E/AndroidRuntime(524): at android.view.View.draw(View.java:6880) 08-25 18:55:53.400: E/AndroidRuntime(524): at android.view.ViewGroup.drawChild(ViewGroup.java:1646) 08-25 18:55:53.400: E/AndroidRuntime(524): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) 08-25 18:55:53.400: E/AndroidRuntime(524): at android.view.ViewGroup.drawChild(ViewGroup.java:1644) 08-25 18:55:53.400: E/AndroidRuntime(524): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) 08-25 18:55:53.400: E/AndroidRuntime(524): at android.view.ViewGroup.drawChild(ViewGroup.java:1644) 08-25 18:55:53.400: E/AndroidRuntime(524): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) 08-25 18:55:53.400: E/AndroidRuntime(524): at android.view.ViewGroup.drawChild(ViewGroup.java:1644) 08-25 18:55:53.400: E/AndroidRuntime(524): at android.view.ViewGroup.dispatchDraw(ViewGroup.java:1373) 08-25 18:55:53.400: E/AndroidRuntime(524): at android.view.View.draw(View.java:6883) 08-25 18:55:53.400: E/AndroidRuntime(524): at android.widget.FrameLayout.draw(FrameLayout.java:357) 08-25 18:55:53.400: E/AndroidRuntime(524): at com.android.internal.policy.impl.PhoneWindow$DecorView.draw(PhoneWindow.java:1862) 08-25 18:55:53.400: E/AndroidRuntime(524): at android.view.ViewRoot.draw(ViewRoot.java:1522) 08-25 18:55:53.400: E/AndroidRuntime(524): at android.view.ViewRoot.performTraversals(ViewRoot.java:1258) 08-25 18:55:53.400: E/AndroidRuntime(524): at android.view.ViewRoot.handleMessage(ViewRoot.java:1859) 08-25 18:55:53.400: E/AndroidRuntime(524): at android.os.Handler.dispatchMessage(Handler.java:99) 08-25 18:55:53.400: E/AndroidRuntime(524): at android.os.Looper.loop(Looper.java:123) 08-25 18:55:53.400: E/AndroidRuntime(524): at android.app.ActivityThread.main(ActivityThread.java:3683) 08-25 18:55:53.400: E/AndroidRuntime(524): at java.lang.reflect.Method.invokeNative(Native Method) 08-25 18:55:53.400: E/AndroidRuntime(524): at java.lang.reflect.Method.invoke(Method.java:507) 08-25 18:55:53.400: E/AndroidRuntime(524): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839) 08-25 18:55:53.400: E/AndroidRuntime(524): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597) 08-25 18:55:53.400: E/AndroidRuntime(524): at dalvik.system.NativeStart.main(Native Method) 08-25 18:55:56.699: I/Process(524): Sending signal. PID: 524 SIG: 9 </code></pre>
 

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