需要帮助。看了很多帖子还是搞不懂。有人可以帮助我。
错误 - [ResultInfo{who=null, request=2, result=-1, data=Intent { act=inline-data dat=content://media/external/images/media/26698(有额外内容)}}]
public int GET_CAM_IMG=2;
public int GET_GAL_IMG=1;
img1.setOnClickListener(new OnClickListener() {
public void onClick(View v){
CharSequence[] names = { "From Gallery", "From Camera" };
new AlertDialog.Builder(context)
.setTitle("Select an option for updating your Profile Picture")
.setItems(names, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int pos) {
// TODO Auto-generated method stub
if (pos == 0) {
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, GET_GAL_IMG);
} else {
Intent i = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
/**
i.putExtra("crop", "true");
i.putExtra("aspectX", 0);
i.putExtra("aspectY", 0);
i.putExtra("outputX", 200);
i.putExtra("outputY", 150);**/
startActivityForResult(i, GET_CAM_IMG);
}}}
)
.setNegativeButton(android.R.string.cancel,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int which) {
}
}).create().show();
}
});}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
switch (requestCode) {
case 2://Camera
Log.d("take","pic");
if (resultCode == -1) {
Uri selectimage=intent.getData();
Log.d("take","pic");
img1.setImageURI(selectimage);
}
break;
case 3://Selecting from Gallery
Log.d("view","pic");
if (resultCode == -1) {
Bitmap bmp_image = null;
Bundle extras = intent.getExtras();
bmp_image = (Bitmap) extras.get("data");
img1.setImageBitmap(bmp_image);
}
break;
}
}
日志输出:
08-21 12:46:46.269: W/dalvikvm(6566): threadid=1: thread exiting with uncaught exception (group=0x41096438)
08-21 12:46:46.299: E/AndroidRuntime(6566): FATAL EXCEPTION: main
08-21 12:46:46.299: E/AndroidRuntime(6566): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { act=inline-data dat=content://media/external/images/media/26702 (has extras) }} to activity {com.inspectreport6784/com.inspectreport6784.NewInspection}: java.lang.NullPointerException
08-21 12:46:46.299: E/AndroidRuntime(6566): at android.app.ActivityThread.deliverResults(ActivityThread.java:3208)
08-21 12:46:46.299: E/AndroidRuntime(6566): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3251)
08-21 12:46:46.299: E/AndroidRuntime(6566): at android.app.ActivityThread.access$1200(ActivityThread.java:143)
08-21 12:46:46.299: E/AndroidRuntime(6566): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1289)
08-21 12:46:46.299: E/AndroidRuntime(6566): at android.os.Handler.dispatchMessage(Handler.java:99)
08-21 12:46:46.299: E/AndroidRuntime(6566): at android.os.Looper.loop(Looper.java:137)
08-21 12:46:46.299: E/AndroidRuntime(6566): at android.app.ActivityThread.main(ActivityThread.java:4961)
08-21 12:46:46.299: E/AndroidRuntime(6566): at java.lang.reflect.Method.invokeNative(Native Method)
08-21 12:46:46.299: E/AndroidRuntime(6566): at java.lang.reflect.Method.invoke(Method.java:511)
08-21 12:46:46.299: E/AndroidRuntime(6566): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1004)
08-21 12:46:46.299: E/AndroidRuntime(6566): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:771)
08-21 12:46:46.299: E/AndroidRuntime(6566): at dalvik.system.NativeStart.main(Native Method)
08-21 12:46:46.299: E/AndroidRuntime(6566): Caused by: java.lang.NullPointerException
08-21 12:46:46.299: E/AndroidRuntime(6566): at com.inspectreport6784.NewInspection.onActivityResult(NewInspection.java:169)
08-21 12:46:46.299: E/AndroidRuntime(6566): at android.app.Activity.dispatchActivityResult(Activity.java:5363)
08-21 12:46:46.299: E/AndroidRuntime(6566): at android.app.ActivityThread.deliverResults(ActivityThread.java:3204)
08-21 12:46:46.299: E/AndroidRuntime(6566): ... 11 more