-2

I'm capturing image using intent and send to my server but when i'm capturing image and compress then some mobile I'm getting bitmap.compress error. So how to solve this problem guys this is my Code

BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 8;
        Bitmap bitmap = BitmapFactory.decodeFile(fileUri.getPath(), options);


        File f = new File(fileUri.getPath());

        OutputStream outputStream = null;
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
        outputStream = new FileOutputStream(f);
        outputStream.flush();
        outputStream.close();

        ImageView image = new ImageView(I_kycActivity.this);
        image.setLayoutParams(new android.view.ViewGroup.LayoutParams(250, 250));
        image.setMaxHeight(400);
        image.setMaxWidth(400);
        image.setPadding(5, 5, 5, 5);
        image.setImageBitmap(bitmap);


        if (phototype.equals("Photo")) {
            img_photo.setImageBitmap(bitmap);
            txtphote.setText(f.getName());
            imgUrl.add(f.getPath());
        }

and error is

12-30 15:33:23.485 9564-9564/com.riya.product.intranet W/System.err: java.lang.NullPointerException: Attempt to invoke virtual method 'boolean android.graphics.Bitmap.compress(android.graphics.Bitmap$CompressFormat, int, java.io.OutputStream)' on a null object reference 12-30 15:33:23.487 9564-9564/com.riya.product.intranet W/System.err: at com.riya.product.salestracker.I_kycActivity.previewCapturedImage(I_kycActivity.java:1124) 12-30 15:33:23.488 9564-9564/com.riya.product.intranet W/System.err: at com.riya.product.salestracker.I_kycActivity.onActivityResult(I_kycActivity.java:1257) 12-30 15:33:23.488 9564-9564/com.riya.product.intranet W/System.err: at android.app.Activity.dispatchActivityResult(Activity.java:6919) 12-30 15:33:23.488 9564-9564/com.riya.product.intranet W/System.err: at android.app.ActivityThread.deliverResults(ActivityThread.java:4174) 12-30 15:33:23.488 9564-9564/com.riya.product.intranet W/System.err: at android.app.ActivityThread.handleSendResult(ActivityThread.java:4221) 12-30 15:33:23.488 9564-9564/com.riya.product.intranet W/System.err: at android.app.ActivityThread.-wrap20(ActivityThread.java) 12-30 15:33:23.488 9564-9564/com.riya.product.intranet W/System.err: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1583) 12-30 15:33:23.488 9564-9564/com.riya.product.intranet W/System.err: at android.os.Handler.dispatchMessage(Handler.java:110) 12-30 15:33:23.488 9564-9564/com.riya.product.intranet W/System.err: at android.os.Looper.loop(Looper.java:203) 12-30 15:33:23.488 9564-9564/com.riya.product.intranet W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6251) 12-30 15:33:23.488 9564-9564/com.riya.product.intranet W/System.err: at java.lang.reflect.Method.invoke(Native Method) 12-30 15:33:23.488 9564-9564/com.riya.product.intranet W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1075) 12-30 15:33:23.488 9564-9564/com.riya.product.intranet W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)

suraj
  • 641
  • 1
  • 7
  • 15

1 Answers1

0

Replace

OutputStream outputStream = null; 

with

OutputStream outputStream = new FileOutputStream(f); 
Yuliwee
  • 327
  • 1
  • 11