我試圖做一個測試:如果statment不工作
- 如果
String==null
或者String.equals(null)
。 - 然後上傳圖片,我從畫廊獲得。
- else然後從mipmap上傳圖片。
但它不工作,我綁也String!=uriBook
和我檢查了uriBook它返回null,當我不從圖庫中選擇圖像。
更新來源:
我使用捆綁因爲ImagePath的是我的第一個片段和我做上傳的片段2
片段1:
if(filePath!=null){bundle.putString("uRI", filePath.toString());}
Frgment 2:
uriBook = String.valueOf(bundle.getString(「uRI」));在
riversRef.putFile(Uri.parse(uriBook))
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>(){}
No content provider: null
java.io.FileNotFoundException: No content provider: null
at android.content.ContentResolver.openTypedAssetFileDescriptor(ContentResolver.java:710)
at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:614)
at android.content.ContentResolver.openInputStream(ContentResolver.java:449)
at com.google.firebase.storage.UploadTask.<init>(Unknown Source)
at com.google.firebase.storage.StorageReference.putFile(Unknown Source)
at com.mydreambook.AddBookFinalFragment.uploadFile(AddBookFinalFragment.java:283)
at com.mydreambook.AddBookFinalFragment.access$000(AddBookFinalFragment.java:39)
at com.mydreambook.AddBookFinalFragment$2.onClick(AddBookFinalFragment.java:174)
private void uploadFile() {
if(uriBook == null) {
Uri imageUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE +
"://" + getResources().getResourcePackageName(R.mipmap.ic_launcher)
+ '/' + getResources().getResourceTypeName(R.mipmap.ic_launcher) + '/' + getResources().getResourceEntryName(R.mipmap.ic_launcher));
final ProgressDialog progressDialog = new ProgressDialog(getActivity());
progressDialog.setTitle("Uploading");
progressDialog.show();
StorageReference storageRefDef = storageDef.getReference();
getRiversRefDef = storageRefDef.child("images/" + nomstaockageImage);
getRiversRefDef.putFile(imageUri)
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
progressDialog.dismiss();
pathStoageInFirebase = getRiversRefDef.getPath();
Log.e(TAG, "path image" + pathStoageInFirebase);
createBook(titreBook, descBook, prixBook, regionBook, viileBook, currentDateandTime, catBook, typeBook, pathStoageInFirebase);
Toast.makeText(getActivity().getApplicationContext(), "File Uploaded ", Toast.LENGTH_LONG).show();
Intent intent = new Intent(getActivity(), AccueilActivity.class);
startActivity(intent);
}
});}
else {
final ProgressDialog progressDialog = new ProgressDialog(getActivity());
progressDialog.setTitle("Uploading");
progressDialog.show();
StorageReference storageRef = storage.getReference();
riversRef = storageRef.child("images/"+nomstaockageImage);
riversRef.putFile(Uri.parse(uriBook))
.addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
progressDialog.dismiss();
pathStoageInFirebase= riversRef.getPath();
Log.e(TAG, "path image"+pathStoageInFirebase);
createBook(titreBook, descBook, prixBook, regionBook, viileBook, currentDateandTime, catBook, typeBook, pathStoageInFirebase);
Toast.makeText(getActivity().getApplicationContext(), "File Uploaded ", Toast.LENGTH_LONG).show();
Intent intent = new Intent(getActivity(), AccueilActivity.class);
startActivity(intent);
}
});
} }
異常錯誤如果uriBook爲null爲什麼源if語句之間不執行?
**更新與圖片debuger **
你的問題還不清楚。還要注意,任何非空對象'equals(null)'返回'false' – nandsito
不完全確定問題是什麼? –
嘗試'uriBook.equals == null'而不是'uriBook.equals(null)' –