2014-01-24 62 views
0

在我的應用程序中,用戶可以從圖庫中選擇一張照片,裁剪並設置爲他們的頭像。 當他們註冊時,我將這張照片發送到服務器。裁剪圖片後:失敗的結果ResultInfo {

爲了發送它,我必須先得到它,但我會得到一個錯誤。

java.lang.RuntimeException: Failure delivering result ResultInfo 
{who=null, request=2, result=-1,  data=Intent { act=inline-data (has extras) }} 
to activity {net.asdasd.asdasd/net.asdasd.activities.Signup}: java.lang.NullPointerException 

這裏是我的代碼:

bSelectPhotoFromFileSignupPage.setOnClickListener(new OnClickListener() { 
        @Override 
        public void onClick(View v) { 

         Intent intent = new Intent(); 

         intent.setType("image/*"); 
         intent.setAction(Intent.ACTION_GET_CONTENT); 

         startActivityForResult(Intent.createChooser(intent, "Complete action using"), PICK_FROM_FILE); 

         dialog.dismiss(); 
        } 

       }); 

    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     if (resultCode != RESULT_OK) return; 

     switch (requestCode) { 
       case PICK_FROM_CAMERA: 
         cropImage(); 

         break; 

       case PICK_FROM_FILE: 
         mImageCaptureUri = data.getData(); 

         cropImage(); 

         break;      

       case CROP_FROM_CAMERA:  

        Uri selectedImage = data.getData(); 
        String[] filePathColumn = { MediaStore.Images.Media.DATA }; 

        Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); 
        cursor.moveToFirst(); 

        int columnIndex = cursor.getColumnIndex(filePathColumn[0]); 

        setAvatarPath(cursor.getString(columnIndex)); 
        // Convert file path into bitmap image using below line. 
        userAvatarBitmap = BitmapFactory.decodeFile(userAvatarPath); 
        //Set the button image to be the newly created image instead of the default 
        iUserAvatar.setImageBitmap(userAvatarBitmap); 

        //delete the temporary file 
        File temporaryAvatarFile = new File(mImageCaptureUri.getPath());    
        if (temporaryAvatarFile.exists()) temporaryAvatarFile.delete(); 

        break; 

     } 
    } 


public class CropOption { 
    public CharSequence title; 
    public Drawable icon; 
    public Intent appIntent; 
} 

public class CropOptionAdapter extends ArrayAdapter<CropOption> { 
    private ArrayList<CropOption> options; 
    private LayoutInflater inflater; 
    private int imageView; 

    public CropOptionAdapter(Context context, ArrayList<CropOption> options, int imageView) { 
     super(context, R.layout.activity_layout_signup, options); 

     this.options = options; 
     this.imageView = imageView; 
     this.inflater = LayoutInflater.from(context); 
    } 

    @Override 
    public View getView(int position, View convertView, ViewGroup group) { 
     if (convertView == null) 
      convertView = inflater.inflate(R.layout.activity_layout_signup, null); 

     CropOption item = options.get(position); 

     if (item != null) { 
      ((ImageView) convertView.findViewById(imageView)).setImageDrawable(item.icon); 

      return convertView; 
     } 

     return null; 
    } 

這裏是整個日誌:

FATAL EXCEPTION: main 
    java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=2, result=-1, data=Intent { act=inline-data (has extras) }} to activity {net.asd.asd/net.asd.activities.Signup}: java.lang.NullPointerException 
    at android.app.ActivityThread.deliverResults(ActivityThread.java:2536) 
    at android.app.ActivityThread.handleSendResult(ActivityThread.java:2578) 
    at android.app.ActivityThread.access$2000(ActivityThread.java:117) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:965) 
    at android.os.Handler.dispatchMessage(Handler.java:99) 
    at android.os.Looper.loop(Looper.java:130) 
    at android.app.ActivityThread.main(ActivityThread.java:3691) 
    at java.lang.reflect.Method.invokeNative(Native Method) 
    at java.lang.reflect.Method.invoke(Method.java:507) 
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907) 
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665) 
    at dalvik.system.NativeStart.main(Native Method) 
    Caused by: java.lang.NullPointerException 
    at android.content.ContentResolver.acquireProvider(ContentResolver.java:743) 
    at android.content.ContentResolver.query(ContentResolver.java:256) 
    at net.asd.activities.Signup.onActivityResult(Signup.java:357) 
    at android.app.Activity.dispatchActivityResult(Activity.java:3934) 
    at android.app.ActivityThread.deliverResults(ActivityThread.java:2532) 
    ... 11 more 

357線如下:

Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null); 

回答

相關問題