应用图片后应用程序崩溃

时间:2013-08-21 15:32:30

标签: android camera

需要帮助。看了很多帖但却无法弄清楚。有人可以帮助我。

  

错误 - [ResultInfo {who = null,request = 2,result = -1,data = Intent {   act = inline-data dat = content:// media / external / images / media / 26698(has   额外的)}}]

    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;
    }
}

Logcat输出:

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

1 个答案:

答案 0 :(得分:0)

您在NullPointerException上有一个169。不知道是什么线......

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

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

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

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

这里没有其他可能发生的事情。唯一的另一种可能性是intent为空,但我不太重视。您的ResultInfo清楚地显示了回复的意图。


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

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

对于简单的空指针,它很容易缩小范围。它为您提供文件,类,方法和行。