title: Android dev - App stopped working, no errors in code
body: <p>I've recently started android app dev, but have came across a problem with the app I'm trying to make. Whenever I load up the app in an emulator (Android 4.2.2 4.00" screen to be exact) it just says "Unfortunately, Russian Roulette has stopped working." 
  Here is my main activity code : </p>
  
  <pre><code>    package com.sabexus.russianroulette;
  
  import java.util.Random;
  
  import android.app.Activity;
  import android.graphics.Color;
  import android.os.Bundle;
  import android.view.Menu;
  import android.view.View;
  import android.widget.Button;
  import android.widget.ImageView;
  import android.widget.TextView;
  import android.widget.Toast;
  
  
  public class MainGameActivity extends Activity{
  
  boolean ReadyToFire;
  int Round;
  Random Dice = new Random();
  int BulletChamber;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main_game);
      final TextView HintTxt = (TextView) findViewById(R.id.LabelHint);
      final ImageView barrelImage = (ImageView) findViewById(R.id.Barrel);
      final ImageView barrelSpinningImage = (ImageView) findViewById(R.id.BarrelSpinning);
      final Button TriggerBtn = (Button)findViewById(R.id.trigger);
      final Button ResetBtn = (Button)findViewById(R.id.ResetButton);
  
      barrelImage.setVisibility(View.VISIBLE);
      barrelSpinningImage.setVisibility(View.GONE);
  
      //variables
      BulletChamber = 1+Dice.nextInt(6);
      Round = 1; 
      ReadyToFire = false;
  
      //Trigger button properties.
      TriggerBtn.setVisibility(View.VISIBLE);
      TriggerBtn.setBackgroundColor(Color.TRANSPARENT);
  
      //Swipe and button touch handlers
      //Trigger Button
      TriggerBtn.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View arg0) {
  
             }
         });
  
      //Reset button
      ResetBtn.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View arg0) {
                 HintTxt.setText("@string/hint");
                 Round = 1;
                 ResetBtn.setVisibility(View.GONE);
             }
         });
  
      //gestures   
      barrelImage.setOnTouchListener(new OnSwipeTouchListener() {
             public boolean onSwipeTop() {
                 Toast.makeText(MainGameActivity.this, "top", Toast.LENGTH_SHORT).show();
                 return true;
             }
             public boolean onSwipeRight() {
                 if(Round!=7){
                     if(ReadyToFire == true){
                         barrelImage.setVisibility(View.GONE);
                         barrelSpinningImage.setVisibility(View.VISIBLE);
                     }
                 }
                 return true;
             }
             public boolean onSwipeLeft() {
                 Toast.makeText(MainGameActivity.this, "left", Toast.LENGTH_SHORT).show();
                 return true;
             }
             public boolean onSwipeBottom() {
                 Toast.makeText(MainGameActivity.this, "bottom", Toast.LENGTH_SHORT).show();
                 return true;
             }
         });
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.main_game, menu);
      return true;
  }
  
  };
  </code></pre>
  
  <p>Here is OnTouchSwipeListener : </p>
  
  <pre><code>package com.sabexus.russianroulette;
  
  import android.view.GestureDetector;
  import android.view.GestureDetector.SimpleOnGestureListener;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.View.OnTouchListener;
  
  public class OnSwipeTouchListener implements OnTouchListener {
  
  @SuppressWarnings("deprecation")
  private final GestureDetector gestureDetector = new GestureDetector(new GestureListener());
  
  public boolean onTouch(final View v, final MotionEvent event) {
      return gestureDetector.onTouchEvent(event);
  }
  
  private final class GestureListener extends SimpleOnGestureListener {
  
      private static final int SWIPE_THRESHOLD = 100;
      private static final int SWIPE_VELOCITY_THRESHOLD = 100;
  
      @Override
      public boolean onDown(MotionEvent e) {
          return super.onDown(e);
      }
  
      @Override
      public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
          boolean result = false;
          try {
              float diffY = e2.getY() - e1.getY();
              float diffX = e2.getX() - e1.getX();
              if (Math.abs(diffX) &gt; Math.abs(diffY)) {
                  if (Math.abs(diffX) &gt; SWIPE_THRESHOLD &amp;&amp; Math.abs(velocityX) &gt; SWIPE_VELOCITY_THRESHOLD) {
                      if (diffX &gt; 0) {
                          result = onSwipeRight();
                      } else {
                          result = onSwipeLeft();
                      }
                  }
              } else {
                  if (Math.abs(diffY) &gt; SWIPE_THRESHOLD &amp;&amp; Math.abs(velocityY) &gt; SWIPE_VELOCITY_THRESHOLD) {
                      if (diffY &gt; 0) {
                          result = onSwipeBottom();
                      } else {
                          result = onSwipeTop();
                      }
                  }
              }
          } catch (Exception exception) {
              exception.printStackTrace();
          }
          return result;
      }
  }
  
  public boolean onSwipeRight() {
      return false;
  }
  
  public boolean onSwipeLeft() {
      return false;
  }
  
  public boolean onSwipeTop() {
      return false;
  }
  
  public boolean onSwipeBottom() {
      return false;
  }
  }
  </code></pre>
  
  <p>Here is my Android Manifest XML :  </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.sabexus.russianroulette"
     android:versionCode="1"
     android:versionName="1.0" &gt;
  
     &lt;uses-sdk
         android:minSdkVersion="8"
         android:targetSdkVersion="17" /&gt;
  
      &lt;application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@android:style/Theme.NoTitleBar.Fullscreen"  &gt;
       &lt;activity
              android:name="com.sabexus.russianroulette.MainGameActivity"
              android:label="@string/app_name" &gt;
             &lt;intent-filter&gt;
                 &lt;action android:name="android.intent.action.MAIN" /&gt;
  
                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
   &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>Lastly, hear is my main activity XML :  </p>
  
  <pre><code>    &lt;ImageView
          android:id="@+id/Barrel"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentRight="true"
          android:layout_alignParentTop="true"
          android:layout_marginRight="67dp"
          android:layout_marginTop="192dp"
          android:src="@drawable/barrel"
          android:contentDescription="@string/desc" /&gt;
  
      &lt;ImageView
          android:id="@+id/BarrelSpinning"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentRight="true"
          android:layout_alignParentTop="true"
          android:layout_marginRight="67dp"
          android:layout_marginTop="192dp"
          android:src="@drawable/barrel_spinning"
          android:contentDescription="@string/desc" /&gt;
  
      &lt;TextView
          android:id="@+id/LabelHint"
          android:layout_width="254dp"
          android:layout_height="88dp"
          android:layout_centerHorizontal="true"
          android:gravity="center"
          android:text="@string/hint"
          android:textAppearance="?android:attr/textAppearanceMedium" /&gt;
  
      &lt;Button
          android:id="@+id/ResetButton"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignRight="@+id/LabelHint"
          android:layout_below="@+id/LabelHint"
          android:text="@string/button"
          android:visibility="gone" /&gt;
  
      &lt;Button
          android:id="@+id/trigger"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignBottom="@+id/Barrel"
          android:layout_marginBottom="32dp"
          android:layout_marginRight="16dp"
          android:layout_toLeftOf="@+id/Barrel"
          android:text="      " /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>also, hear is my logcat log :</p>
  
  <pre><code>    05-17 17:37:35.744: E/Trace(1094): error opening trace file: No such file or directory (2)
  05-17 17:37:35.862: D/AndroidRuntime(1094): Shutting down VM
  05-17 17:37:35.862: W/dalvikvm(1094): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
  05-17 17:37:35.884: E/AndroidRuntime(1094): FATAL EXCEPTION: main
  05-17 17:37:35.884: E/AndroidRuntime(1094): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.sabexus.russianroulette/com.sabexus.russianroulette.MainGameActivity}: java.lang.NullPointerException
  05-17 17:37:35.884: E/AndroidRuntime(1094):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2106)
  05-17 17:37:35.884: E/AndroidRuntime(1094):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
  05-17 17:37:35.884: E/AndroidRuntime(1094):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
  05-17 17:37:35.884: E/AndroidRuntime(1094):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
  05-17 17:37:35.884: E/AndroidRuntime(1094):     at android.os.Handler.dispatchMessage(Handler.java:99)
  05-17 17:37:35.884: E/AndroidRuntime(1094):     at android.os.Looper.loop(Looper.java:137)
  05-17 17:37:35.884: E/AndroidRuntime(1094):     at android.app.ActivityThread.main(ActivityThread.java:5041)
  05-17 17:37:35.884: E/AndroidRuntime(1094):     at java.lang.reflect.Method.invokeNative(Native Method)
  05-17 17:37:35.884: E/AndroidRuntime(1094):     at java.lang.reflect.Method.invoke(Method.java:511)
  05-17 17:37:35.884: E/AndroidRuntime(1094):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  05-17 17:37:35.884: E/AndroidRuntime(1094):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  05-17 17:37:35.884: E/AndroidRuntime(1094):     at dalvik.system.NativeStart.main(Native Method)
  05-17 17:37:35.884: E/AndroidRuntime(1094): Caused by: java.lang.NullPointerException
  05-17 17:37:35.884: E/AndroidRuntime(1094):     at android.app.Activity.findViewById(Activity.java:1839)
  05-17 17:37:35.884: E/AndroidRuntime(1094):     at com.sabexus.russianroulette.MainGameActivity.&lt;init&gt;(MainGameActivity.java:22)
  05-17 17:37:35.884: E/AndroidRuntime(1094):     at java.lang.Class.newInstanceImpl(Native Method)
  05-17 17:37:35.884: E/AndroidRuntime(1094):     at java.lang.Class.newInstance(Class.java:1319)
  05-17 17:37:35.884: E/AndroidRuntime(1094):     at android.app.Instrumentation.newActivity(Instrumentation.java:1054)
  05-17 17:37:35.884: E/AndroidRuntime(1094):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
  05-17 17:37:35.884: E/AndroidRuntime(1094):     ... 11 more
  </code></pre>
  
  <p>Sorry for the long, noobish post but i really cant find out whats wrong with it :( Thanks in advance :D</p>