이미지뷰에 이미지가 표현이 안되는데 레이아웃 문제인지 액티비티 문제인지 알려주세요.

조회수 2366회

파일브라우저에서 이미지를 선택하게 되면 다른 activity 로 path 를 넘겨 이미지를 보여주게 되는 앱인데 파일 브라우저에서 이미지 클릭시 다른 activity 로 넘기는 부분과 이미지 경로를 받아서 ImageView 에 보여주는 activity 가 추가되었습니다.

문제 되는 부분으로 짐작가는 곳이 서브 액티비티와 레이아웃인데 컴파일 했을때는 오류메시지 발생을 없었습니다.

참조한 사이트 입니다. http://mainia.tistory.com/1198?category=251412

메인액티비티

        protected void onListItemClick(ListView l, View v, int position, long id) {

            File file = new File(path.get(position));
            String filename = file.getName();
            String ext = filename.substring(filename.lastIndexOf('.') + 1, filename.length());

            if (ext.equals("JPG") || ext.equals("jpg")) {
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                bundle.putString("totalpath", file.getPath());
                intent.putExtras(bundle);
                intent.setClass(PoemList.this, PoemClicked.class);

                startActivityForResult(intent, 0);
            }

서브액티비티

//    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.select_image);

        TextView txtImgName = (TextView)findViewById(R.id.jpgname);
        ImageView jpgView = (ImageView)findViewById(R.id.jpgview);
        //jpgView.setOnClickListener(clickListener);

        Intent intent = getIntent();
        if(intent!=null){
            String path = intent.getStringExtra("totalpath");
            txtImgName.setText(path);

            BitmapFactory.Options options = new BitmapFactory.Options();
            options.inSampleSize = 2;
            Bitmap bm = BitmapFactory.decodeFile(path, options);
            jpgView.setImageBitmap(bm);
        }

레이아웃

//
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/jpgview"
        android:maxHeight="200dp"
        android:maxWidth="200dp"
        android:adjustViewBounds="true"
        android:layout_gravity="center"
        android:layout_marginBottom="20dp"/>
  • (•́ ✖ •̀)
    알 수 없는 사용자

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)