error share png image (taken from firebase) and put in an image view

Asked

Viewed 145 times

1

happens the following. I have a share button, when I try to share an image from inside my drawable, beauty it goes, now when I try to share the image that came from firebase, there will "it closes the app" PS: I’m beginner, I know it’s because of the image, because with the local image it will, I just don’t know how to solve. Thank you in advance for the people who try to help me

HERE I UPLOAD THE FIREBASE IMAGE INTO AN IMAGEVIEW:

 btnFrase = (Button) findViewById(R.id.idBtnLoadPhoto);
    btnFrase.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Log.i("IMAGEM", "Aqui carrega imagem");
            Glide.with(getApplicationContext()).load("https://firebasestorage.googleapis.com/caminho da imagem").into(img);
        }
    });

HERE IS THE SHARE METHOD:

private void sharedImage(){
    // Vamos carregar a imagem em um bitmap
    Bitmap b = BitmapFactory.decodeResource(getResources(), R.id.idPhoto); //idPhoto é o ID da minha imageView
    Intent share = new Intent(Intent.ACTION_SEND);
    //setamos o tipo da imagem
    share.setType("image/png");
    ByteArrayOutputStream bytes = new ByteArrayOutputStream();
    // comprimomos a imagem
    b.compress(Bitmap.CompressFormat.PNG, 100, bytes);
    // Gravamos a imagem

    String path = MediaStore.Images.Media.insertImage(getContentResolver(), b, "testetituloimagem", null);

    // criamos uam Uri com o endereço que a imagem foi salva
    Uri imageUri =  Uri.parse(path);
    // Setmaos a Uri da imagem
    share.putExtra(Intent.EXTRA_STREAM, imageUri);
    // chama o compartilhamento
    startActivity(Intent.createChooser(share, "Selecione"));
}

ERROR ON ANDROID MONITOR

10-20 17:10:47.906 3652-3652/br.com.quanticoapps.frases E/AndroidRuntime: FATAL EXCEPTION: main
                                                                      Process: br.com.quanticoapps.frases, PID: 3652
                                                                      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
                                                                          at br.com.quanticoapps.frases.MainActivity.sharedImage(MainActivity.java:152)
                                                                          at br.com.quanticoapps.frases.MainActivity.checarPermissao(MainActivity.java:176)
                                                                          at br.com.quanticoapps.frases.MainActivity.access$000(MainActivity.java:34)
                                                                          at br.com.quanticoapps.frases.MainActivity$2.onClick(MainActivity.java:72)
                                                                          at android.view.View.performClick(View.java:5610)
                                                                          at android.view.View$PerformClick.run(View.java:22265)
                                                                          at android.os.Handler.handleCallback(Handler.java:751)
                                                                          at android.os.Handler.dispatchMessage(Handler.java:95)
                                                                          at android.os.Looper.loop(Looper.java:154)
                                                                          at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                                          at java.lang.reflect.Method.invoke(Native Method)
                                                                          at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
                                                                          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
  • Places the error that appears on Android Monitor

  • I put the bug in the post. I hope I can help

  • I debugged and realized that the object "b" (which is Bitmap), is null when I try to point to the imageview, and when I put an image of my drawable folder, it is not null, or the error is because it is not taking the image and assigning to the object "b".

  • 1

    Do something like this - Bitmap.createBitmap(imageView.getDrawingCache());

  • Icaro closes the app and gives this error: java.lang.Nullpointerexception: Attempt to invoke virtual method 'int android.graphics.Bitmap.getWidth()' on a null Object Reference

  • 1

    Icaro, now it’s time, THANK YOU! what you missed in your solution was just put before this here: imageView.buildDrawingCache();

  • can show how the result was in the code ?

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.