0

So I am almost totally new to Android Development. I played around with it a long time ago in the Froyo days but it's so different now and it has been so long that I am basically new to the whole thing.

So, I am trying to get a Camera application started to play around with the API and see what I can do. I generated a Fullscreen App using the Android Studio Wizard and then copied the Camera application example code from the Android website.

The application builds without any problems, it installs to my Nexus 4 emulator fine, but when I try to run it on the emulator it simply opens and closes again immediately saying "Unfortunately, Cam has stopped"

I'm not going to make you read through all the code I have so far, rather my question is not so much what is my problem but just what can I do, as a newcomer, to determine the problem? I have tried adding an alert dialog to the onCreate method of my Activity Class using the following code:

AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setMessage("Begun");
alert.show();

However nothing happens. I just get the same unhelpful message that the application has unfortunately stopped.

Luke
  • 2,434
  • 9
  • 39
  • 64
  • 1
    Please post your logcat showing the error log. Rather, that's what you can do to figure it out. Should give you an error, then a ways down will say "Caused by...", that's your problem. – ChiefTwoPencils Jun 06 '14 at 20:19
  • 1
    go to the logcat window, when your application crash you will see a text which will say to you what happens. It's the stacktrace. – Marco Acierno Jun 06 '14 at 20:19
  • Don't appear som change in the screen? – Chefes Jun 06 '14 at 20:24
  • Thanks for the tip about logcat... that's really helpful. However, the information seems somewhat limited. It tells me there is a NullPointerException, but nothing about which variable has caused it or what line it occured on, just the method it occured in. `java.lang.NullPointerException at com.luketim.cam.cam.CameraPreview.surfaceCreated(CameraPreview.java:34)` – Luke Jun 06 '14 at 20:43
  • Oh, a few lines up I am told there is a permission failure on the Camera permissions. What could be causing this? – Luke Jun 06 '14 at 20:44
  • Okay, now I am getting the following message from nothing to do with my code but seemingly the cause of another NullPointerException: `gralloc_alloc: Mismatched usage flags: 328 x 546` – Luke Jun 06 '14 at 21:01

1 Answers1

0

You forgot AlerDialog.Builder create();

AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setMessage("Begun");
alert.create().show();
ElaGorilaki
  • 227
  • 6
  • 20