Error adding image to URI - "cannot find Symbol class fromFile"

Asked

Viewed 154 times

0

Guys, I can’t find the reason why Android Studio does not recognize the method Uri.fromFile(). I searched several places but nothing. My code is like this:

foto.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent irParaCamera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

            caminhoArquivo = getExternalFilesDir(null) + "/" + System.currentTimeMillis() + ".png";
            File arquivo = new File(caminhoArquivo);

            Uri localFoto = new Uri.fromFile(arquivo);
            irParaCamera.putExtra(MediaStore.EXTRA_OUTPUT, localFoto);

            startActivityForResult(irParaCamera, 123);
        }
    });

The strange thing is that Android Studio comes to suggest that I use this method, but when I use it does not recognize it. Follow the Imports:

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.provider.MediaStore;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import java.io.File;

Am I doing something wrong? Thanks in advance.

1 answer

0

I discovered the bug. In the excerpt:

Uri localFoto = new Uri.fromFile(arquivo);

There is no "new". Just take it out it worked.

Hugs

Browser other questions tagged

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