0
Привет, может кто-нибудь помочь мне исправить это. Я получаю сообщение об ошибке в этой строке Файл imageFile = new File (photoUri); говорит, что файл конструктора (photoUri) не определен, даже если у меня есть этот contructor на методе, который будет его называть. вот мой код.Ошибка на Uri in android
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQ){
if (resultCode == RESULT_OK) {
Uri photoUri = null;
if (data == null){
Toast.makeText(this, "Image saved successfully", Toast.LENGTH_LONG).show();
photoUri = fileUri;
} else {
photoUri = data.getData();
Toast.makeText(this, "Image saved successfully in: " + data.getData(), Toast.LENGTH_LONG).show();
}
showPhoto(photoUri);
} else if (resultCode == RESULT_CANCELED)
{
Toast.makeText(this, "Cancelled", Toast.LENGTH_SHORT).show();
} else
{
Toast.makeText(this, "Callout for image capture failed!", Toast.LENGTH_LONG).show();
}
}
}
private void showPhoto(Uri photoUri)
{
File imageFile = new File(photoUri);
if (imageFile.exists())
{
Drawable oldDrawable = photoImage.getDrawable();
if (oldDrawable != null) { ((BitmapDrawable)oldDrawable).getBitmap().recycle();
}
Bitmap bitmap = BitmapFactory.decodeFile(imageFile.getAbsolutePath());
BitmapDrawable drawable = new BitmapDrawable(this.getResources(), bitmap);
photoImage.setScaleType(ImageView.ScaleType.FIT_CENTER);
photoImage.setImageDrawable(drawable);
}
}
ошибка исчезла, но она отображает снимок. – lolliloop