###前提・実現したいこと
ここに質問したいことを詳細に書いてください
下記のエラーがなぜ発生しているのか、どこをかいぜんすればいいのかについて教えていただければ幸いです。
###発生している問題・エラーメッセージ
Error:(22, 13) エラー: シンボルを見つけられません
シンボル: クラス TextView
場所: クラス MainActivity
Error:(27, 25) エラー: パッケージRは存在しません
Error:(29, 21) エラー: シンボルを見つけられません
シンボル: クラス TextView
場所: クラス MainActivity
Error:(29, 44) エラー: パッケージRは存在しません
Error:(33, 46) エラー: パッケージRは存在しません
Error:(35, 40) エラー: パッケージRは存在しません
Error:(56, 16) エラー: シンボルを見つけられません
シンボル: 変数 Environment
場所: クラス MainActivity
Error:(56, 66) エラー: シンボルを見つけられません
シンボル: 変数 Environment
場所: クラス MainActivity
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
Compilation failed; see the compiler error output for details.
エラーメッセージ
###該当のソースコード ```lang-java import android.app.Activity; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.ParcelFileDescriptor; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.widget.Button; import android.widget.ImageView; import java.io.FileDescriptor; import java.io.IOException; public class MainActivity extends AppCompatActivity { private static final int RESULT_PICK_IMAGEFILE = 1001; private ImageView imageView; private Button button; private TextView dcimPath; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); dcimPath = (TextView)findViewById(R.id.text_view); // ギャラリーのパスを取得する dcimPath.setText("ギャラリーのPath: "+getGalleryPath()); imageView = (ImageView)findViewById(R.id.image_view); button = (Button)findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // ACTION_OPEN_DOCUMENT is the intent to choose a file via the system's file browser. Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT); // Filter to only show results that can be "opened", such as a // file (as opposed to a list of contacts or timezones) intent.addCategory(Intent.CATEGORY_OPENABLE); // Filter to show only images, using the image MIME data type. // it would be "*/*". intent.setType("image/*"); startActivityForResult(intent, RESULT_PICK_IMAGEFILE); } }); } private String getGalleryPath() { return Environment.getExternalStorageDirectory() + "/" + Environment.DIRECTORY_DCIM + "/"; } @Override public void onActivityResult(int requestCode, int resultCode, Intent resultData) { // The ACTION_OPEN_DOCUMENT intent was sent with the request code // READ_REQUEST_CODE. If the request code seen here doesn't match, it's the // response to some other intent, and the code below shouldn't run at all. if (requestCode == RESULT_PICK_IMAGEFILE && resultCode == Activity.RESULT_OK) { // The document selected by the user won't be returned in the intent. // Instead, a URI to that document will be contained in the return intent // provided to this method as a parameter. // Pull that URI using resultData.getData(). Uri uri = null; if (resultData != null) { uri = resultData.getData(); Log.i("", "Uri: " + uri.toString()); try { Bitmap bmp = getBitmapFromUri(uri); imageView.setImageBitmap(bmp); } catch (IOException e) { e.printStackTrace(); } } } } private Bitmap getBitmapFromUri(Uri uri) throws IOException { ParcelFileDescriptor parcelFileDescriptor = getContentResolver().openFileDescriptor(uri, "r"); FileDescriptor fileDescriptor = parcelFileDescriptor.getFileDescriptor(); Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor); parcelFileDescriptor.close(); return image; } }
###試したこと
参考URLhttps://akira-watson.com/android/gallery.html
上記を元に作成(コピペ)
しかしエラー....
###補足情報(言語/FW/ツール等のバージョンなど)
Android stadio 2.3.3で作成中
回答2件
あなたの回答
tips
プレビュー