Note that there are some explanatory texts on larger screens.

plurals
  1. POGetting Null Pointer and I have no idea why
    primarykey
    data
    text
    <p>I am having a <code>NPE</code> on some code and I have no clue why. I am sure it is something trivial, but I can't seem to find it - here is what I am trying to do.</p> <p>Snap a photo, detect faces, if there are no faces then display the image on an <code>ImageView</code> and allow the user the option to snap another photo.</p> <p>Here is my code:</p> <pre><code>if (facesFound &lt; 1) { ImageView imageView = (ImageView) findViewById(R.id.false_view); TextView textView = (TextView) findViewById(R.id.badPicText); textView.setText(R.string.noFaceFive); imageView.setImageBitmap(bitmap565); } </code></pre> <p>this is inside my method:</p> <pre><code>private void detectFaces() { //Here is the method I use to snap a photo then detect for faces: } public void processCameraImage(Intent intent) { setContentView(R.layout.detectlayout); // detectlayout ImageView imageView = (ImageView) findViewById(R.id.image_view); // image_view cameraBitmap = (Bitmap) intent.getExtras().get("data"); imageView.setImageBitmap(cameraBitmap); detectFaces(); } </code></pre> <p>The odd thing is, when a face is detected, it works just fine - and puts them image on an <code>ImageView</code> saying it did, as so</p> <pre><code>if (facesFound &gt; 0){ //face detection code //write the bmp to an output stream, compress ImageView imageView = (ImageView) findViewById(R.id.image_view); TextView textView = (TextView) findViewById(R.id.textViewGoodPic); textView.setText(R.string.yesFace); imageView.setImageBitmap(bitmap565); } </code></pre> <p>Anyone know where I might be going wrong?</p> <p>Thanks!</p> <p><em>EDIT</em>: the app is crashing when the app detects no faces and I try to write the photo and some text to the <code>ImageView</code>.</p> <p><em>EDIT</em>: Here is the <code>logcat</code>:</p> <pre><code>11-18 19:42:39.825: ERROR/AndroidRuntime(4244): FATAL EXCEPTION: main 11-18 19:42:39.825: ERROR/AndroidRuntime(4244): java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=100, result=-1, data=Intent { act=inline-data (has extras) }} to activity {com.project.dtf/com.project.dtf.DTF}: java.lang.NullPointerException 11-18 19:42:39.825: ERROR/AndroidRuntime(4244): at android.app.ActivityThread.deliverResults(ActivityThread.java:3589) 11-18 19:42:39.825: ERROR/AndroidRuntime(4244): at android.app.ActivityThread.handleSendResult(ActivityThread.java:3631) 11-18 19:42:39.825: ERROR/AndroidRuntime(4244): at android.app.ActivityThread.access$3000(ActivityThread.java:129) 11-18 19:42:39.825: ERROR/AndroidRuntime(4244): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2137) 11-18 19:42:39.825: ERROR/AndroidRuntime(4244): at android.os.Handler.dispatchMessage(Handler.java:99) 11-18 19:42:39.825: ERROR/AndroidRuntime(4244): at android.os.Looper.loop(Looper.java:143) 11-18 19:42:39.825: ERROR/AndroidRuntime(4244): at android.app.ActivityThread.main(ActivityThread.java:4701) 11-18 19:42:39.825: ERROR/AndroidRuntime(4244): at java.lang.reflect.Method.invokeNative(Native Method) 11-18 19:42:39.825: ERROR/AndroidRuntime(4244): at java.lang.reflect.Method.invoke(Method.java:521) 11-18 19:42:39.825: ERROR/AndroidRuntime(4244): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868) 11-18 19:42:39.825: ERROR/AndroidRuntime(4244): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626) 11-18 19:42:39.825: ERROR/AndroidRuntime(4244): at dalvik.system.NativeStart.main(Native Method) 11-18 19:42:39.825: ERROR/AndroidRuntime(4244): Caused by: java.lang.NullPointerException 11-18 19:42:39.825: ERROR/AndroidRuntime(4244): at com.project.dtf.DTF.detectFaces(DTF.java:130) 11-18 19:42:39.825: ERROR/AndroidRuntime(4244): at com.project.dtf.DTF.processCameraImage(DTF.java:90) 11-18 19:42:39.825: ERROR/AndroidRuntime(4244): at com.project.dtf.DTF.onActivityResult(DTF.java:57) 11-18 19:42:39.825: ERROR/AndroidRuntime(4244): at android.app.Activity.dispatchActivityResult(Activity.java:3890) 11-18 19:42:39.825: ERROR/AndroidRuntime(4244): at android.app.ActivityThread.deliverResults(ActivityThread.java:3585) </code></pre> <p><em>EDIT</em>: Still having issues =/</p> <p>Here are both calls:</p> <pre><code>if (facesFound &lt; 1) { setContentView(R.layout.detectfalse); ImageView imageView = (ImageView) findViewById(R.id.false_view); TextView textView = (TextView) findViewById(R.id.badPicText); textView.setText(R.string.noFace); imageView.setImageBitmap(bitmap565); } </code></pre> <p><em>AND</em></p> <pre><code>if (facesFound &gt; 0) { showToast(this, "Face Detected!"); //do stuff setContentView(R.layout.detectlayout); ImageView imageView = (ImageView) findViewById(R.id.image_view); TextView textView = (TextView) findViewById(R.id.textViewGoodPic); textView.setText(R.string.yesFace); imageView.setImageBitmap(bitmap565); } </code></pre> <p>Keep in mind, I did <code>setContentView</code> in this method:</p> <pre><code>public void processCameraImage(Intent intent) { setContentView(R.layout.detectlayout); // detectlayout ImageView imageView = (ImageView) findViewById(R.id.image_view); // image_view cameraBitmap = (Bitmap) intent.getExtras().get("data"); imageView.setImageBitmap(cameraBitmap); detectFaces(); } </code></pre> <p>before the <code>facedetect</code> class is even called, is that where I am going wrong?</p>
    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.
    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