메인액티비티
@Override
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);
}
if (file.isDirectory()) {
if (file.canRead())
getDir(path.get(position));
else {
new AlertDialog.Builder(this)
.setIcon(R.mipmap.ic_launcher)
.setTitle("[" + file.getName() + "] folder can't be read!")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
}
} else {
new AlertDialog.Builder(this)
.setIcon(R.mipmap.ic_launcher)
.setTitle("[" + file.getName() + "]")
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
}).show();
}
}
}
서브액티비티
package com.example.poeticalworks;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.TextView;
public class PoemClicked extends Activity {
@Override
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);
}
}
}
전체설명
파일브라우저에서 이미지를 선택하게
되면 다른 activity 로 path 를 넘겨 이미지를 보여줘야 되는데
startActivityForResult 부분에서 오류나면서 앱이 꺼져버리네요.....
오류관련 부분입니다.
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.poeticalworks, PID: 6846
android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.poeticalworks/com.example.poeticalworks.PoemClicked}; have you declared this activity in your AndroidManifest.xml?
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1772)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1496)
at android.app.Activity.startActivityFromChild(Activity.java:4328)
at android.app.Activity.startActivityFromChild(Activity.java:4304)
at android.app.Activity.startActivityForResult(Activity.java:3809)
at android.app.Activity.startActivityForResult(Activity.java:3739)
at com.example.poeticalworks.PoemList.onListItemClick(PoemList.java:80)
at android.app.ListActivity$2.onItemClick(ListActivity.java:319)
at android.widget.AdapterView.performItemClick(AdapterView.java:305)
at android.widget.AbsListView.performItemClick(AbsListView.java:1185)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:3237)
at android.widget.AbsListView$3.run(AbsListView.java:4184)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5556)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:967)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)