Note that there are some explanatory texts on larger screens.

plurals
  1. POCamera NullPointerException
    primarykey
    data
    text
    <p>Im working off the Android camera tutorial, SDK 11. For some reason I'm getting a Null Pointer within handleCameraPhoto(). The only thing I see is "Failure delivering result ResultInfo{who=null, request=100, result=-1, data=null} to activity", but I can't sort out why.</p> <pre><code>&lt;uses-permission android:name="android.permission.CAMERA" /&gt; &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt; </code></pre> <p>Activity:</p> <pre><code>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_camera); // create Intent to take a picture and return control to the calling application Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE); // create a file to save the image intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name ///Toast.makeText(this, "File Uri"+fileUri.toString(), Toast.LENGTH_LONG).show(); // start the image capture Intent startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE) { if (resultCode == RESULT_OK) { // Image captured and saved to fileUri specified in the Intent handleCameraPhoto(data); } else if (resultCode == RESULT_CANCELED) { // User cancelled the image capture finish(); } else { // Image capture failed, advise user finish(); Toast.makeText(this, "Image capture failed, quiting", Toast.LENGTH_LONG).show(); } } } /** * * @param intent */ private void handleCameraPhoto(Intent data) { Toast.makeText(this, "Image saved to:\n" + data.getData(), Toast.LENGTH_LONG).show(); } /** Create a file Uri for saving an image or video */ private static Uri getOutputMediaFileUri(int type){ return Uri.fromFile(getOutputMediaFile(type)); } /** Create a File for saving an image or video */ private static File getOutputMediaFile(int type){ // To be safe, you should check that the SDCard is mounted // using Environment.getExternalStorageState() before doing this. File mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), "Shindiggy"); // This location works best if you want the created images to be shared // between applications and persist after your app has been uninstalled. // Create the storage directory if it does not exist if (! mediaStorageDir.exists()){ if (! mediaStorageDir.mkdirs()){ Log.d("Shindiggy", "failed to create directory"); return null; } } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; if (type == MEDIA_TYPE_IMAGE){ mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_"+ timeStamp + ".jpg"); } else { return null; } return mediaFile; } </code></pre> <p>Error Cat</p> <pre><code>11-19 11:39:06.782: W/dalvikvm(7719): threadid=1: thread exiting with uncaught exception (group=0x41549700) 11-19 11:39:06.782: E/AndroidRuntime(7719): FATAL EXCEPTION: main 11-19 11:39:06.782: E/AndroidRuntime(7719): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=-1, data=null} to activity {com.shindiggy.shindiggy/com.shindiggy.shindiggy.CameraActivity}: java.lang.NullPointerException 11-19 11:39:06.782: E/AndroidRuntime(7719): at android.app.ActivityThread.deliverResults(ActivityThread.java:3367) 11-19 11:39:06.782: E/AndroidRuntime(7719): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3410) 11-19 11:39:06.782: E/AndroidRuntime(7719): at android.app.ActivityThread.access$1100(ActivityThread.java:141) 11-19 11:39:06.782: E/AndroidRuntime(7719): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1304) 11-19 11:39:06.782: E/AndroidRuntime(7719): at android.os.Handler.dispatchMessage(Handler.java:99) 11-19 11:39:06.782: E/AndroidRuntime(7719): at android.os.Looper.loop(Looper.java:137) 11-19 11:39:06.782: E/AndroidRuntime(7719): at android.app.ActivityThread.main(ActivityThread.java:5103) 11-19 11:39:06.782: E/AndroidRuntime(7719): at java.lang.reflect.Method.invokeNative(Native Method) 11-19 11:39:06.782: E/AndroidRuntime(7719): at java.lang.reflect.Method.invoke(Method.java:525) 11-19 11:39:06.782: E/AndroidRuntime(7719): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737) 11-19 11:39:06.782: E/AndroidRuntime(7719): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 11-19 11:39:06.782: E/AndroidRuntime(7719): at dalvik.system.NativeStart.main(Native Method) 11-19 11:39:06.782: E/AndroidRuntime(7719): Caused by: java.lang.NullPointerException 11-19 11:39:06.782: E/AndroidRuntime(7719): at com.shindiggy.shindiggy.CameraActivity.handleCameraPhoto(CameraActivity.java:68) 11-19 11:39:06.782: E/AndroidRuntime(7719): at com.shindiggy.shindiggy.CameraActivity.onActivityResult(CameraActivity.java:51) 11-19 11:39:06.782: E/AndroidRuntime(7719): at android.app.Activity.dispatchActivityResult(Activity.java:5322) 11-19 11:39:06.782: E/AndroidRuntime(7719): at android.app.ActivityThread.deliverResults(ActivityThread.java:3363) 11-19 11:39:06.782: E/AndroidRuntime(7719): ... 11 more </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload