title: Android: java.lang.RuntimeException: Unable to start activity ComponentInfo
body: <p>I'm fairly new to android so I apologize if this is a total noob question. I have spent hours at searching for similar subjects but i couldn't find the solution.</p>
  
  <p>I'm getting this error when trying to run the app:</p>
  
  <pre><code>&gt; java.lang.RuntimeException: Unable to start activity
  &gt; ComponentInfo{com.avnsoft.runtracker/com.avnsoft.runtracker.RunActivity}:
  &gt; java.lang.NullPointerException
  </code></pre>
  
  <p>Stacktrace:</p>
  
  <pre><code>&gt; AndroidRuntime(21828): FATAL EXCEPTION: main 06-07 00:35:24.792:
  &gt; E/AndroidRuntime(21828): java.lang.RuntimeException: Unable to start
  &gt; activity
  &gt; ComponentInfo{com.avnsoft.runtracker/com.avnsoft.runtracker.RunActivity}:
  &gt; java.lang.NullPointerException 06-07 00:35:24.792:
  &gt; E/AndroidRuntime(21828): at
  &gt; android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
  &gt; 06-07 00:35:24.792: E/AndroidRuntime(21828): at
  &gt; android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
  &gt; 06-07 00:35:24.792: E/AndroidRuntime(21828): at
  &gt; android.app.ActivityThread.access$600(ActivityThread.java:141) 06-07
  &gt; 00:35:24.792: E/AndroidRuntime(21828): at
  &gt; android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
  &gt; 06-07 00:35:24.792: E/AndroidRuntime(21828): at
  &gt; android.os.Handler.dispatchMessage(Handler.java:99) 06-07
  &gt; 00:35:24.792: E/AndroidRuntime(21828): at
  &gt; android.os.Looper.loop(Looper.java:137) 06-07 00:35:24.792:
  &gt; E/AndroidRuntime(21828): at
  &gt; android.app.ActivityThread.main(ActivityThread.java:5041) 06-07
  &gt; 00:35:24.792: E/AndroidRuntime(21828): at
  &gt; java.lang.reflect.Method.invokeNative(Native Method) 06-07
  &gt; 00:35:24.792: E/AndroidRuntime(21828): at
  &gt; java.lang.reflect.Method.invoke(Method.java:511) 06-07 00:35:24.792:
  &gt; E/AndroidRuntime(21828): at
  &gt; com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  &gt; 06-07 00:35:24.792: E/AndroidRuntime(21828): at
  &gt; com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560) 06-07
  &gt; 00:35:24.792: E/AndroidRuntime(21828): at
  &gt; dalvik.system.NativeStart.main(Native Method) 06-07 00:35:24.792:
  &gt; E/AndroidRuntime(21828): Caused by: java.lang.NullPointerException
  &gt; 06-07 00:35:24.792: E/AndroidRuntime(21828): at
  &gt; android.view.ViewGroup.addViewInner(ViewGroup.java:3338) 06-07
  &gt; 00:35:24.792: E/AndroidRuntime(21828): at
  &gt; android.view.ViewGroup.addView(ViewGroup.java:3210) 06-07
  &gt; 00:35:24.792: E/AndroidRuntime(21828): at
  &gt; android.view.ViewGroup.addView(ViewGroup.java:3186) 06-07
  &gt; 00:35:24.792: E/AndroidRuntime(21828): at
  &gt; com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:289)
  &gt; 06-07 00:35:24.792: E/AndroidRuntime(21828): at
  &gt; com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:279)
  &gt; 06-07 00:35:24.792: E/AndroidRuntime(21828): at
  &gt; android.app.Activity.setContentView(Activity.java:1901) 06-07
  &gt; 00:35:24.792: E/AndroidRuntime(21828): at
  &gt; com.avnsoft.runtracker.SingleFragmentActivity.onCreate(SingleFragmentActivity.java:21)
  &gt; 06-07 00:35:24.792: E/AndroidRuntime(21828): at
  &gt; com.avnsoft.runtracker.RunActivity.onCreate(RunActivity.java:11) 06-07
  &gt; 00:35:24.792: E/AndroidRuntime(21828): at
  &gt; android.app.Activity.performCreate(Activity.java:5104) 06-07
  &gt; 00:35:24.792: E/AndroidRuntime(21828): at
  &gt; android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
  &gt; 06-07 00:35:24.792: E/AndroidRuntime(21828): at
  &gt; android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
  &gt; 06-07 00:35:24.792: E/AndroidRuntime(21828): ... 11 more
  </code></pre>
  
  <p>activity_fragment.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragmentContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    /&gt;
  </code></pre>
  
  <p>activity_run.xml:</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      xmlns:tools="http://schemas.android.com/tools"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:paddingBottom="@dimen/activity_vertical_margin"
      android:paddingLeft="@dimen/activity_horizontal_margin"
      android:paddingRight="@dimen/activity_horizontal_margin"
      android:paddingTop="@dimen/activity_vertical_margin"
      tools:context=".RunActivity" &gt;
  
      &lt;TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="@string/hello_world" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>fragment_run.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      &gt;
      &lt;TableRow&gt;
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:gravity="right"
              android:paddingRight="5sp"
              android:text="@string/started"
              /&gt;
          &lt;TextView android:id="@+id/run_startedTextView"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              /&gt;
      &lt;/TableRow&gt;
      &lt;TableRow&gt;
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:gravity="right"
              android:paddingRight="5sp"
              android:text="@string/latitude"
              /&gt;
          &lt;TextView android:id="@+id/run_latitudeTextView"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              /&gt;
      &lt;/TableRow&gt;
      &lt;TableRow&gt;
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:gravity="right"
              android:paddingRight="5sp"
              android:text="@string/longitude"
              /&gt;
          &lt;TextView android:id="@+id/run_longitudeTextView"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              /&gt;
      &lt;/TableRow&gt;
      &lt;TableRow&gt;
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:gravity="right"
              android:paddingRight="5sp"
              android:text="@string/altitude"
              /&gt;
          &lt;TextView android:id="@+id/run_altitudeTextView"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              /&gt;
      &lt;/TableRow&gt;
      &lt;TableRow&gt;
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:gravity="right"
              android:paddingRight="5sp"
              android:text="@string/elapsed_time"
              /&gt;
          &lt;TextView android:id="@+id/run_durationTextView"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:textSize="25sp"
              /&gt;
      &lt;/TableRow&gt;
      &lt;LinearLayout
          android:orientation="horizontal"
          android:layout_height="wrap_content"
          &gt;
          &lt;Button android:id="@+id/run_startButton"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_weight="1"
              android:text="@string/start"
              /&gt;
          &lt;Button android:id="@+id/run_stopButton"
              android:layout_width="0dp"
              android:layout_height="wrap_content"
              android:layout_weight="1"
              android:text="@string/stop"
              /&gt;
      &lt;/LinearLayout&gt;
  &lt;/TableLayout&gt;
  </code></pre>
  
  <p>SingleFragmentActivity.java:</p>
  
  <pre><code>package com.avnsoft.runtracker;
  
  
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentActivity;
  import android.support.v4.app.FragmentManager;
  import android.widget.FrameLayout;
  
  public abstract class SingleFragmentActivity extends FragmentActivity {
      protected static final String FRAGMENT_TAG = "SingleFragmentActivity.Fragment";
  
      protected abstract Fragment createFragment();
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          FrameLayout fl = new FrameLayout(this);
          fl.setId(R.id.fragmentContainer);
          setContentView(fl);
  
          FragmentManager manager = getSupportFragmentManager();
          Fragment fragment = manager.findFragmentById(R.id.fragmentContainer);
  
          if (fragment == null) {
              fragment = createFragment();
              manager.beginTransaction()
                  .add(R.id.fragmentContainer, fragment)
                  .commit();
          }
      }
  }
  </code></pre>
  
  <p>RunActivity.java:</p>
  
  <pre><code>package com.avnsoft.runtracker;
  
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.Menu;
  
  public class RunActivity extends SingleFragmentActivity {
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_run);
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.run, menu);
          return true;
      }
  
      @Override
      protected Fragment createFragment() {
          return new RunFragment();
      }
  
  }
  </code></pre>
  
  <p>and finally RunFragment.java:</p>
  
  <pre><code>package com.avnsoft.runtracker;
  
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.Button;
  import android.widget.TextView;
  
  public class RunFragment extends Fragment {
  
      private Button mStartButton, mStopButton;
      private TextView mStartedTextView,
      mLatitudeTextView,
      mLongitudeTextView,
      mAltitudetextView,
      mDurationTextView;
  
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setRetainInstance(true);
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
      //Create View   
      View view = inflater.inflate(R.layout.fragment_run, container, false);
  
      //Assign widgets
      mStartedTextView = (TextView)view.findViewById(R.id.run_startedTextView);
      mLatitudeTextView = (TextView)view.findViewById(R.id.run_latitudeTextView);
      mLongitudeTextView = (TextView)view.findViewById(R.id.run_longitudeTextView);
      mAltitudetextView = (TextView)view.findViewById(R.id.run_altitudeTextView);
      mDurationTextView = (TextView)view.findViewById(R.id.run_durationTextView);
  
      mStartButton = (Button)view.findViewById(R.id.run_startButton);
      mStopButton = (Button)view.findViewById(R.id.run_stopButton);
  
      return view;
  
      }
  
  }
  </code></pre>
  
  <p>I apologize for the excessive amount of code but after spending 4 hours in trying to find the problem i have no idea where is it... 
  Can someone please help? Thanks!</p>