<!-- language: none -->
04-23 11:47:01.904: E/AndroidRuntime(12396):
java.lang.RuntimeException: Unable to resume activity {com.t4t.sp/com.t4t.sp.SignUpActivity}:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=111, result=-1, data=Intent { act=content://media/external/images/media/3809 (has extras) }} to activity {com.t4t.sp/com.t4t.sp.SignUpActivity}:
java.lang.NullPointerException
我无法找出活动无法产生结果的原因,我想要的是我正在启动编辑意图,编辑后我想提供uri到我的onactivity结果。
编辑:
这是我的创建方法
的代码`protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGESS);
setContentView(R.layout.activity_sign_up);
mUsername=(EditText)findViewById(R.id.usernameField);
mPassword=(EditText)findViewById(R.id.passwordField);
mImage=(ImageView) findViewById(R.id.imageView1);
medit=(Button)findViewById(R.id.edit);
medit.setVisibility(View.GONE);
mImage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v)
{
Intent choosePhotoIntent=new Intent(Intent.ACTION_GET_CONTENT); choosePhotoIntent.setType("image/*");
choosePhotoIntent.putExtra("crop", "true");
choosePhotoIntent.putExtra("outputX", 128);
choosePhotoIntent.putExtra("outputY", 128);
choosePhotoIntent.putExtra("aspectX", 1);
choosePhotoIntent.putExtra("aspectY", 1);
choosePhotoIntent.putExtra("scale", true);
startActivityForResult(choosePhotoIntent, PICK_PHOTO_REQUEST);
}
});
`
这是我的结果代码的活动,我得到数据的空值,因为当我试图获取url时,它在那里说空指针:
@SuppressLint("NewApi")
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Log.e("resultcode",Integer.toString(resultCode));
Log.e("requestcode",Integer.toString(requestCode));
String fileType = null;
if(resultCode==RESULT_OK){
if(requestCode==PICK_PHOTO_REQUEST)
{
medit.setVisibility(View.VISIBLE);
mImageUri=data.getData();
String imageUri=getRealPathFromURI(mImageUri);
mImage.setImageURI(Uri.parse(imageUri));
}
@Mighter
答案 0 :(得分:0)
在您的返回网址类中:
Activity act=this;
Intent returnIntent = new Intent();
//Log.i("class2","uri: "+uri);
returnIntent.setData(uri);
//Log.i("class2","return: "+returnIntent.getData().toString());
act.setResult(Activity.RESULT_OK, returnIntent);
act.finish();
在调用类中:
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//Log.i("class1","finish");
}
启动编辑课程时。
Intent i=new Intent(this,Editing.class);
//Log.i("class1","start");
this.startActivityForResult(i, 0);
如果您的代码与我的代码相同,请尝试添加日志注释,以便更好地了解问题所在。
答案 1 :(得分:0)
如果你看一下你得到的错误:
java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=111, result=-1, data=Intent { act=content://media/external/images/media/3809 (has extras) }} to activity {com.t4t.sp/com.t4t.sp.SignUpActivity}:
您可以看到Intent
作为data
参数传递给onActivityResult()
:
data=Intent { act=content://media/external/images/media/3809 (has extras) }
此Intent
包含附加内容和操作,但不包含 DATA 字段。这就是您在致电null
时获得data.getData()
的原因。
您正在寻找的网址是在操作中返回的(这有点愚蠢的恕我直言,但除此之外)。你需要这样做:
String imageUri=data.getAction();
mImage.setImageURI(Uri.parse(imageUri));