ファイヤーベースのストレージに画像をアップロードしようとしています。キャプチャボタンを押すと、アプリケーションがクラッシュし、このエラーが発生します。 java.lang.NullPointerException:仮想メソッド 'android.content.res.XmlResourceParser android.content.pm.ProviderInfo.loadXmlMetaData(android.content。私のコードではnullのオブジェクト参照のpm.PackageManager、java.lang.Stringで)」ファイヤーベースのストレージに画像をアップロードできません
このライン上のUri photoURI = FileProvider.getUriForFile(this, "com.faum.faum_expert.fileprovider", photoFile);
:
private ImageView ivKitchen1,ivKitchen2,ivKitchen3;
private Button btnCapture1,btnCapture2,btnCapture3;
private TextView tvKitchenSnaps;
private StorageReference snapsStorage;
private static final int CAMERA_REQUEST_CODE = 1;
private ProgressDialog mProgress;
private Uri filepath;
String mCurrentPhotoPath;
private File createImageFile() throws IOException {
// Create an image file name
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
String imageFileName = "JPEG_" + timeStamp + "_";
File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
File image = File.createTempFile(
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
mCurrentPhotoPath = "file:" + image.getAbsolutePath();
return image;
}
private void dispatchTakePictureIntent() {
Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// Ensure that there's a camera activity to handle the intent
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
// Create the File where the photo should go
File photoFile = null;
try {
photoFile = createImageFile();
} catch (IOException ex) {
}
if (photoFile != null) {
Uri photoURI = FileProvider.getUriForFile(this,
"com.faum.faum_expert.fileprovider",
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, CAMERA_REQUEST_CODE);
}
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.kitchen_snaps);
snapsStorage = FirebaseStorage.getInstance().getReference();
ivKitchen1 = (ImageView)findViewById(R.id.ivKitchen1);
btnCapture1 = (Button)findViewById(R.id.btnCapture1);
mProgress = new ProgressDialog(this);
btnCapture1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivityForResult(intent, CAMERA_REQUEST_CODE);*/
dispatchTakePictureIntent();
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == CAMERA_REQUEST_CODE && resultCode == RESULT_OK){
mProgress.setMessage("Uploading...");
mProgress.show();
Uri uri = data.getData();
StorageReference filepath = snapsStorage.child("Photos").child(uri.getLastPathSegment());
filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(Kitchen_Snaps.this, "Upload Successful!", Toast.LENGTH_SHORT).show();
mProgress.dismiss();
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Toast.makeText(Kitchen_Snaps.this, "Upload Failed!", Toast.LENGTH_SHORT).show();
}
});
}
}
マニフェストファイル
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.CAMERA" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the 'MyLocation' functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!--
-
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.faum.faum_expert.fileprovider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths"></meta-data>
</provider>
-->
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Social_Connect" />
<activity android:name=".User_sign" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
<activity android:name=".Personal_Information" />
<activity android:name=".Contact_Infrormation" />
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps" />
<activity android:name=".Kitchen_Snaps" />
<activity
android:name=".Navigation_Drawer"
android:label="@string/title_activity_navigation__drawer"
android:theme="@style/AppTheme" />
<activity android:name=".New_Deal" />
<activity android:name=".New_Deal_Time" />
<activity android:name=".New_Deal_List" />
<activity android:name=".New_Deal_Confirmation"></activity>
</application>
は、私はマニフェストファイルを掲示し、あなたのマニフェストすぎ –
を投稿しています。 –