Ich versuche, das Kunden-Thumbnail zu seinem Konto hinzufügen, indem Sie das Foto erfassen und das Gesicht durch eine andere Aktivität zuschneiden.Es funktioniert gut im Emulator, aber wenn auf dem tatsächlichen Gerät ausgeführt wurde error.Help benötigt.Image Capturing Android Problem
public void imageload(View v)
{
switch (v.getId()) {
case imageView_new_customer:
final CharSequence[] options = {"Take Photo", "Choose from Gallery", "Cancel"};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Add Photo!");
builder.setItems(options, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int item) {
if (options[item].equals("Take Photo")) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
ContextWrapper contextWrapper = new ContextWrapper(getApplicationContext());
File directory = contextWrapper.getDir("Image", Context.MODE_PRIVATE);
File f = new File(Environment.getExternalStorageDirectory(), "temp.jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
startActivityForResult(intent, 1);
} else if (options[item].equals("Choose from Gallery")) {
Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(intent, 2);
} else if (options[item].equals("Cancel")) {
dialog.dismiss();
}
}
});
builder.show();
break;
}
}
Cropping Aktivität:
if (getIntent().getStringExtra("Source").equals("camera"))
{
// Set image for cropping
ContextWrapper contextWrapper = new ContextWrapper(getApplicationContext());
File directory = contextWrapper.getDir("Image", Context.MODE_PRIVATE);
File f = new File(Environment.getExternalStorageDirectory().toString());
for (File temp : f.listFiles()) {
if (temp.getName().equals("temp.jpg")) {
f = temp;
break;
}
}
Fehler:
java.lang.RuntimeException: Unable to start activity ComponentInfo{loginscreen.example.com.girviapp/loginscreen.example.com.girviapp.CropImage}: java.lang.NullPointerException: Attempt to get length of null array
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2555)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2629)
at android.app.ActivityThread.access$800(ActivityThread.java:182)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5706)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1033)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:828)
Caused by: java.lang.NullPointerException: Attempt to get length of null array
at loginscreen.example.com.girviapp.CropImage.onCreate(CropImage.java:43)
at android.app.Activity.performCreate(Activity.java:6092)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1112)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2502)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2629)
at android.app.ActivityThread.access$800(ActivityThread.java:182)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1474)
at android.os.Handler.dispatchMessage(Handler.java:111)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5706)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1033)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:828)
für (Dateitemp: f.listFiles()), das ist Zeile 43 –
Überprüfen Sie, ob f tatsächlich korrekt ausgefüllt wird. Haben Sie die write_external_storage-Berechtigung in Ihrem Android-Manifest deklariert? Wenn Sie die Targeting-API 23 oder höher verwenden, müssen Sie die gleiche Berechtigung vom Benutzer anfordern. – seanAshmore
Ich denke, dass Sie wirklich die Lese-Speicherberechtigung benötigen, aber schreiben Sie lesen und schreiben – seanAshmore