0

こんにちは、誰でもこれを修正するのを手伝ってくれます。この行でエラーが発生しますFile imageFile = new File(photoUri); コンストラクター File(photoUri) は未定義であると言って、それを呼び出すメソッドにそのコンストラクターがあります。ここに私のコードがあります。

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);
 }  

}

4

1 に答える 1

0

インスタンスtoString()を呼び出すphotoUri

showPhoto(photoUri.toString());

Uri.toString()この URI のエンコードされた文字列表現を返します。

于 2013-06-25T09:05:33.207 に答える