android - Onactivityresult returning null bitmap, selecting image from device not working -


I am trying to choose a picture from all the pictures on the device. I was working this code on the last app but for some reason this will not work. A Nalpointer exception gives me an exception while trying to set the selected image to an image view, so I think the bitmap is empty. I tried many tutorials and used that code, rewritten everything, but every time the same problem occurs. I have tried many devices, running Android 4.4 and Android 4.2.2 (so this is not just a KitKat problem).

My code:

  Public class Iconize activity expanded {Public ImageView ivMain; Linear layout topscrolls; Bitmap bitmap; Int REQUEST_CODE = 1; Frame layout flow; Reference C; @ Override Protected Zero (InstanceStat saved from bundle) {// Todo auto-generated method stub super. Connet (Saved Instantstate); setContentView (R.layout.activity_iconize); C = getApplicationContext (); Topscrolls = (linear layout) this.findViewById (R.id.ll_topscrollview); Fl = (frame layout) this.findViewById (RIDFreemelAutholder); // Some questions do not relate to this question // ///// Last reference C = getApplicationContext (); PickImageFromDevice (); } @ Override Protected Zero ontop () {// TODO Auto generated method stub super.onStop (); Println ("Stop"); } Public Zero pickImageFromDevice () intent = intent (new intention); intent.setType ("image / *"); Intent.setAction (Intent.ACTION_GET_CONTENT); Intent.addCategory (Intent.CATEGORY_OPENABLE); StartActivityForResult (intent, REQUEST_CODE); } {IfCode == REQUEST_CODE & amp; amp; resultCode == Activity.RESULT_OK} try {if (! Bitmap = null) {bitmap} to protect @Override zero onActivityResult (integer requestCode, integer resultCode, intent data) Recycle (); } InputStream stream = getContentResolver (). OpenInputStream (data.getData ()); Bitmap = bitmapfender Aodestream (stream); Stream.close (); ivMain.setImageBitmap (bitmap); } Hold (FileNotFoundException e) {e.printStackTrace (); } Hold (IOException e) {e.printStackTrace (); } Hold (NullPointerException e) {e.printStackTrace (); } Super.onActivityResult (requestCode, ResultsCode, Data); }}   

and stacktrace:

  04-21 10: 28: 18.499: w / system Er (25 9 51): java.lang.NullPointerException 04-21 October: 28: 18.519: W / System.err (25951): com.sa.iconize.Iconize.onActivityResult (Iconize.java:114) on 04- October 21: 28: 18.519: W / Systems. ARR (25191): Android. App Activity DIPAPActivative Result (activity. Java-2: 5423) 04-21 10: 28: 18.519: W / Systems. ARR (25191): Android. App On Activitatrad deliverResults (ActivityThread.java:3361) October 04-21: 28: 18.519: W / System.err (25,951): android.app.ActivityThread.handleSendResult (ActivityThread.java:3408) on October 04-21: 28: 18.519: W / System.err (25,951): 28 :: 18.519: W / System.err (25,951): android.app.ActivityThread.access $ 1300 (ActivityThread.java:135) android.app.ActivityThread on October 04-21 $ H. Ondlemes (ActivityTrad.Java 2424) 04-21 10: 28: 18.519: W / Systems. ARR (25191): Android.OS Handler. Dispatch Message (Handler. Java 1.02) 04-21 10:28: 18.519: W / Systems. Er (25191): Android. Los. Looper Lope (Luor.JYR 36) 04-21 10: 28: 18.51 9: W / Systems. ARR (25191): Android. App Activitat.mine (activitytrade.java t 10101) 04-21 10: 28: 18.519: W / system. Er (25 9 51): at java.lang.reflect. Method.invokeNative (Basic Method) 04-21 10: 28: 18.519: W / Systems. Er (25 9 51): at java.lang.reflect.Method.invoke (Method.java less15) 04-21 10:28: 18.519: W / System.err (25,951): com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run (ZygoteInit.java:779) 04-21 October: 28: 18.519: W / System.err (25951): com.android.internal.os.ZygoteInit.main (ZygoteInit.java lesson9) 04 - October 21: 28: 18.519: W / System.err (25951): dalvik.system.NativeStart.main (native resident method)   

Where is the error where the error occurs :

  ivMain.setImageBitmap (bitmap);   

I think I'm really forgetting something, because it should not be difficult and I did this work on previous projects ... <

Are you sure that ivMain is started properly?

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -