-1

需要帮助。看了很多帖子还是搞不懂。有人可以帮助我。

错误 - [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
4

1 回答 1

0

你有一个NullPointerException在线169. 不知道那是什么线...

我们知道您在这段代码中:

Uri selectimage=intent.getData();
Log.d("take","pic");
img1.setImageURI(selectimage);

因为你的ResultInfo节目request=2, result=-1。这意味着你的空指针在那里。

最可能的原因img1是 null。我看到你在上面使用它,但不知道它是否在以后的范围内。在不知道如何或何时初始化的情况下,很难说。

这里没有太多其他可能发生的事情。唯一的另一种可能性是intent空值,但我不认为它太多。您ResultInfo清楚地表明了回来的意图。


以后可以在logcat中自己找到这些东西。只需寻找类似的东西:

Caused by: java.lang.NullPointerException
    at com.inspectreport6784.NewInspection.onActivityResult(NewInspection.java:169)

对于简单的空指针,很容易缩小范围。它将文件、类、方法和行合二为一。

于 2013-08-21T17:20:32.223 回答