Note that there are some explanatory texts on larger screens.

plurals
  1. POApplication Crash when using CAMERA - Android
    primarykey
    data
    text
    <p>I've written an application which should take a picture and then show it on the screen for modifications. When trying it on the eclipse emulator the camera won't work, so I'm trying it on my Galaxy Nexus Smart Phone.</p> <p>Nevertheless when running it on my SP the application will crash saying that <code>it unfortunally stopped working</code>.</p> <p>When executing the app this is what exactly happens:</p> <ol> <li>I click on the camera button and the camera interface gets opened </li> <li>After taking the picture it gives me the choice to discard it or open it</li> <li>If I click on discard the application returns to normal usage</li> <li>If I click on open the application crashes as mentioned above</li> </ol> <p>I googled a little and found out that you need permissions to use hardware devices <a href="http://developer.android.com/tools/device.html" rel="nofollow">check here</a>, so I created the file <code>/etc/udev/rules.d/51-android.rules</code> and this is its content:</p> <blockquote> <p>SUBSYSTEM=="USB", ATTR{IDVENDOR}=="18d1", MODE="0666, "GROUP="plugdev" SUBSYSTEM=="USB", ATTR{IDVENDOR}=="04e8", MODE="0666, "GROUP="plugdev" SUBSYSTEM=="USB", ATTR{IDVENDOR}=="0bb4", MODE="0666, "GROUP="plugdev"</p> </blockquote> <p>But still I won't be able to use camera.</p> <p>Here are the permissions I declared in my manifest file:</p> <pre><code>&lt;uses-permission android:name="android.permission.INTERNET" /&gt; &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /&gt; &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt; &lt;uses-permission android:name="android.permission.CAMERA" /&gt; &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt; &lt;uses-feature android:name="android.hardware.camera" /&gt; &lt;uses-feature android:name="android.hardware.camera.autofocus" /&gt; </code></pre> <p>Here is the code I use to launch the camera intent:</p> <pre><code>//create new Intent Intent cameraIntent = new Intent( android.provider.MediaStore.ACTION_IMAGE_CAPTURE ); //get something back from the activity we are starting startActivityForResult( cameraIntent, CAMERA_PICTURE_REQUEST ); </code></pre> <p>And this is the code for processing the result:</p> <pre><code>public void onActivityResult( int requestCode, int resultCode, Intent imageReturnedIntent ) { if( resultCode == RESULT_OK ) { if( requestCode == GALLERY_PICTURE_REQUEST ) { selectedImageUri = imageReturnedIntent.getData(); Log.d( TAG, selectedImageUri ); Intent intent = new Intent( DVAHLUI_SuperviseActivity.this, DVAHLUI_SelectImageContentActivity.class ); intent.setData( selectedImageUri ); startActivity( intent ); } if( requestCode == CAMERA_PICTURE_REQUEST ) { selectedImageUri = imageReturnedIntent.getData(); Log.d( TAG, selectedImageUri ); Intent intent = new Intent( DVAHLUI_SuperviseActivity.this, DVAHLUI_SelectImageContentActivity.class ); intent.setData( selectedImageUri ); startActivity( intent ); } } } </code></pre> <p>This is the getPath() function causing the Java Null pointer exception:</p> <pre><code>public String getPath( Uri uri ) { String[] filePathColumn = { android.provider.MediaStore.Images.Media.DATA }; LINE 343 --&gt; Cursor cursor = getContentResolver().query( uri, filePathColumn, null, null, null ); cursor.moveToFirst(); int columnIndex = cursor.getColumnIndexOrThrow( filePathColumn[0] ); String filePath = cursor.getString( columnIndex ); cursor.close(); return filePath; } </code></pre> <p>Can you please tell me what's going wrong?</p> <p><strong>FOGOT TO POST LOGCAT:</strong></p> <pre><code>E/AndroidRuntime(27859): FATAL EXCEPTION: main E/AndroidRuntime(27859): java.lang.RuntimeException: Failure delivering result ResultInfo{who=supervise, request=1, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.DVA_HLUI/com.DVA_HLUI.DVAHLUI_TabModeActivity}: java.lang.NullPointerException E/AndroidRuntime(27859): at android.app.ActivityThread.deliverResults(ActivityThread.java:3141) E/AndroidRuntime(27859): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3184) E/AndroidRuntime(27859): at android.app.ActivityThread.access$1100(ActivityThread.java:130) E/AndroidRuntime(27859): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1243) E/AndroidRuntime(27859): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(27859): at android.os.Looper.loop(Looper.java:137) E/AndroidRuntime(27859): at android.app.ActivityThread.main(ActivityThread.java:4745) E/AndroidRuntime(27859): at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime(27859): at java.lang.reflect.Method.invoke(Method.java:511) E/AndroidRuntime(27859): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) E/AndroidRuntime(27859): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) E/AndroidRuntime(27859): at dalvik.system.NativeStart.main(Native Method) E/AndroidRuntime(27859): Caused by: java.lang.NullPointerException E/AndroidRuntime(27859): at android.content.ContentResolver.acquireUnstableProvider(ContentResolver.java:1094) E/AndroidRuntime(27859): at android.content.ContentResolver.query(ContentResolver.java:354) E/AndroidRuntime(27859): at android.content.ContentResolver.query(ContentResolver.java:313) E/AndroidRuntime(27859): at com.DVA_HLUI.DVAHLUI_SuperviseActivity.getPath(DVAHLUI_SuperviseActivity.java:343) E/AndroidRuntime(27859): at com.DVA_HLUI.DVAHLUI_SuperviseActivity.onActivityResult(DVAHLUI_SuperviseActivity.java:312) E/AndroidRuntime(27859): at android.app.ActivityGroup.dispatchActivityResult(ActivityGroup.java:122) E/AndroidRuntime(27859): at android.app.ActivityThread.deliverResults(ActivityThread.java:3137) E/AndroidRuntime(27859): ... 11 more </code></pre>
    singulars
    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.
 

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