2017-11-25 43 views
-5

這是我的代碼。不瞭解如何解決它。查看很多代碼但失敗。所以張貼在這裏。Android中的java.lang.NullPointerException捕獲

storageReference = FirebaseStorage.getInstance().getReference(); 

    progressDialog = new ProgressDialog(this); 

    select.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); 

      startActivityForResult(intent,CAMERA_REQUEST_CODE); 
     } 
    }); 
} 

@Override 
protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
    super.onActivityResult(requestCode, resultCode, data); 

    if(requestCode == CAMERA_REQUEST_CODE && resultCode == RESULT_OK) 
    { 
     progressDialog.setMessage("Uploading picture"); 
     progressDialog.show(); 
     Uri uri = data.getData(); 

     StorageReference filePath = storageReference.child("Photos").child(uri.getLastPathSegment()); 
     //StorageReference filepath = storageReference.child("CapturedPhotos").child(uri.getLastPathSegment()); 

     filePath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() { 
      @Override 
      public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { 
       progressDialog.dismiss(); 

       // Uri downloadUri = taskSnapshot.getDownloadUrl(); 
       // Picasso.with(Storage_Capture_Picture.this).load(downloadUri).fit().centerCrop().into(imageView); 

       Toast.makeText(Storage_Capture_Picture.this,"Uploaded",Toast.LENGTH_SHORT).show(); 
      } 
     }); 
    } 

logcat的

11-26 14:57:07.953 2912年至2912年/ com.a.firebaseapp E/AndroidRuntime:致命異常:主 工藝:com.a.firebaseapp,PID: 2912 java.lang.RuntimeException:無法恢復活動{com.a.firebaseapp/com.a.firebaseapp.Storage_Capture_Picture}:java.lang.RuntimeException:傳遞結果失敗ResultInfo {who = null,request = 1,result = - 1,data = Intent {act = inline-data(has extras)}} to activity {com.a.firebaseapp/com.a.firebaseapp.Storage_Capture_Picture}:java.lang.NullPointerException 在android.app.ActivityThread.performResumeActivity(ActivityThread.java:2786) 在android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2815) 在android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2248) 在在android.app.ActivityThread.access $ 900(ActivityThread.java:135) at android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1202) (android.app.ActivityThread.java:3736) at android.app.ActivityThread.access at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.Activ ityThread.main(ActivityThread.java:5019) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal .os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:779) 在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) 在dalvik.system.NativeStart.main(本機方法) 引起通過:java.lang.RuntimeException:失敗的結果ResultInfo {who = null,request = 1,result = -1,data = Intent {act = inline-data(has extras)}} to activity {com.a.firebaseapp/com.a.firebaseapp.Storage_Capture_Picture}:java.lang.NullPointerException at android.app.ActivityThread.deliverResults(Activit (ActivityThread.java:3363) at android.app.ActivityThread.performResumeActivity(ActivityThread.java:2773) at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:2815) at android.app.ActivityThread.handleLaunchActivity(ActivityThread。 java:2248) at android.app.ActivityThread.handleRelaunchActivity(ActivityThread.java:3736) at android.app.ActivityThread.access $ 900(ActivityThread.java:135) at android.app.ActivityThread $ H.handleMessage(ActivityThread .java:1202) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5019) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:779) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595) at dalvik.system.NativeStart.main (Native Method) 引起:java.lang。NullPointerException at com.a.firebaseapp.Storage_Capture_Picture.onActivityResult(Storage_Capture_Picture.java:64) at android.app.Activity.dispatchActivityResult(Activity.java:5423) at android.app.ActivityThread.deliverResults(ActivityThread.java:3359 )

我試圖製作一個應用程序,使用火基存儲,將捕獲圖像並將其存儲到我的Firebase存儲。

當我運行我的應用程序,它運行良好。我移動到相機捕捉圖像,我選擇好的按鈕,它顯示我不幸停下來。

我添加了所有的權限和gradle這個文件build.Shows我這兩個錯誤

顯示java.lang.NullPointerException

了java.lang.RuntimeException:無法恢復活動

+0

您應該將這些錯誤發佈到您的LogCat –

+0

'progressDialog == null' – greenapps

+0

當您想要全尺寸圖像時,您必須創建一個文件來存儲它並將該文件的Uri作爲圖像捕獲意圖。請參閱[文檔中的示例代碼](https://developer.android.com/training/camera/photobasics.html#TaskPath)。 –

回答

0

如果您在活動中這樣做,您必須初始化您的ProgressDialog,如

progressDialog = new ProgressDialog(ActivityName.this); 

,如果你是在一個片段這樣做,你必須初始化你ProgressDialog像

progressDialog = new ProgressDialog(getActivity()); 

你是不是正確初始化progressDialog。

+0

嘗試過,但沒有奏效。 –

相關問題