title: FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity
body: <p>When i run my application in my phone which has android version 4.2.2. it will work correctly, but when i run it again in other phone like 4.1.2, ice cream sandwich, only the splashscreen will work correctly. and after 5 seconds, the application already stop. </p>
  
  <p>This is my Logcat Error:</p>
  
  <pre><code> FATAL EXCEPTION: main
   java.lang.RuntimeException: Unable to start activity ComponentInfo{dtournavigation.android/dtournavigation.android.MyActivity}: java.lang.NullPointerException
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2097)
      at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2122)
      at android.app.ActivityThread.access$600(ActivityThread.java:140)
      at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1228)
      at android.os.Handler.dispatchMessage(Handler.java:99)
      at android.os.Looper.loop(Looper.java:137)
      at android.app.ActivityThread.main(ActivityThread.java:4895)
      at java.lang.reflect.Method.invokeNative(Native Method)
      at java.lang.reflect.Method.invoke(Method.java:511)
      at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:994)
      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:761)
      at dalvik.system.NativeStart.main(Native Method)
   Caused by: java.lang.NullPointerException
      at dtournavigation.android.fragments.MainFragment.isGPSEnabled(MainFragment.java:2277)
      at dtournavigation.android.fragments.MainFragment.onPrepareOptionsMenu(MainFragment.java:2164)
      at android.support.v4.app.Fragment.performPrepareOptionsMenu(Fragment.java:1574)
      at android.support.v4.app.FragmentManagerImpl.dispatchPrepareOptionsMenu(FragmentManager.java:1980)
      at android.support.v4.app.FragmentActivity.onPreparePanel(FragmentActivity.java:475)
      at com.android.internal.policy.impl.PhoneWindow.preparePanel(PhoneWindow.java:471)
      at com.android.internal.policy.impl.PhoneWindow.invalidatePanelMenu(PhoneWindow.java:817)
      at android.app.Activity.invalidateOptionsMenu(Activity.java:2667)
      at android.support.v4.app.ActivityCompatHoneycomb.invalidateOptionsMenu(ActivityCompatHoneycomb.java:29)
      at android.support.v4.app.FragmentActivity.supportInvalidateOptionsMenu(FragmentActivity.java:633)
      at android.support.v4.app.Fragment.setHasOptionsMenu(Fragment.java:781)
      at dtournavigation.android.fragments.MainFragment.onCreate(MainFragment.java:325)
      at android.support.v4.app.Fragment.performCreate(Fragment.java:1455)
      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:893)
      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104)
      at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:682)
      at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1460)
      at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:556)
      at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1178)
      at android.app.Activity.performStart(Activity.java:5173)
      at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2070)
      ... 11 more
  </code></pre>
  
  <p>This is my Manifest File:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="dtournavigation.android"
      android:versionCode="8"
      android:versionName="2.0.1" &gt;
      &lt;uses-sdk android:minSdkVersion="8" 
                android:targetSdkVersion="13"
                android:maxSdkVersion="19"/&gt;
  
      &lt;uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.SEND_SMS"/&gt;
  
      &lt;uses-permission android:name="android.permission.READ_CONTACTS" /&gt;
  
  
      &lt;!-- Android Maps API V2 --&gt;
      &lt;permission
           android:name="edu.usf.cutr.opentripplanner.android.permission.MAPS_RECEIVE"
           android:protectionLevel="signature"/&gt;
      &lt;uses-permission android:name="edu.usf.cutr.opentripplanner.android.permission.MAPS_RECEIVE"/&gt;  
      &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/&gt;
      &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/&gt;
      &lt;uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/&gt;
      &lt;!-- The following permission is not required to use
           Google Maps Android API v2, but is recommended. --&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/&gt;
  
      &lt;uses-feature
          android:glEsVersion="0x00020000"
          android:required="true"/&gt;
  
      &lt;supports-screens
          android:anyDensity="true"
          android:largeScreens="true"
          android:normalScreens="true"
          android:smallScreens="true" /&gt;
  
      &lt;application
          android:name="dtournavigation.android.OTPApp"  
          android:icon="@drawable/dtour_logo"
          android:label="@string/app_name"
          android:allowBackup="true"&gt;
  
          &lt;uses-library android:name="com.google.android.maps" /&gt;  
          &lt;activity
              android:name="dtournavigation.android.MyActivity"
              android:label="@string/app_name"
              android:launchMode="singleTop"
              android:theme="@style/MyTheme"
              android:windowSoftInputMode="stateHidden" 
              android:screenOrientation="portrait"&gt;
  
              &lt;meta-data
              android:name="android.support.PARENT_ACTIVITY"
              android:value="dtournavigation.android.MainActivity" /&gt;
  
          &lt;/activity&gt;
          &lt;activity android:name="dtournavigation.android.SettingsActivity" 
              android:theme="@style/MyTheme"
              android:screenOrientation="portrait"
              android:windowSoftInputMode="stateHidden" &gt;
          &lt;/activity&gt;
          &lt;service android:name="dtournavigation.android.NavigationService" /&gt;
            &lt;meta-data android:name="com.google.android.gms.version" 
          android:value="@integer/google_play_services_version" /&gt;
          &lt;meta-data
              android:name="com.google.android.maps.v2.API_KEY"
              android:value="AIzaSyAoJe7kIY7m6EGyZ3cPt7JCiLDwh9DZ09w"/&gt;
          &lt;activity android:name="dtournavigation.android.passtype.PassType"
              android:theme="@style/MyTheme"&gt;&lt;/activity&gt;
          &lt;activity android:name=".GlobalApplication"
              android:theme="@style/MyTheme"&gt;&lt;/activity&gt;
          &lt;activity android:name="dtournavigation.android.fragments.DirectionListFragments"
              android:theme="@style/MyTheme"
              android:screenOrientation="portrait"&gt;
               &lt;/activity&gt;
        &lt;activity android:name="dtournavigation.android.SplashScreen"
              android:screenOrientation="portrait"
              android:theme="@style/NoTitle"&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;activity android:name="dtournavigation.android.SMS"
              android:theme="@style/MyTheme"
              android:screenOrientation="portrait"&gt;
               &lt;/activity&gt;
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>This is my MyActivity.java File</p>
  
  <pre><code>package dtournavigation.android;
  
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.List;
  
  import org.opentripplanner.v092snapshot.api.model.Itinerary;
  import org.opentripplanner.v092snapshot.api.model.Leg;
  
  import android.content.Intent;
  import android.database.Cursor;
  import android.net.Uri;
  import android.os.Bundle;
  import android.provider.ContactsContract;
  import android.support.v4.app.Fragment;
  import android.support.v4.app.FragmentActivity;
  import android.support.v4.app.FragmentManager;
  import android.support.v4.app.FragmentTransaction;
  import android.util.Log;
  import com.google.android.gms.maps.model.LatLng;
  import dtournavigation.android.R;
  import dtournavigation.android.fragments.DirectionListFragment;
  import dtournavigation.android.fragments.MainFragment;
  import dtournavigation.android.listeners.DateCompleteListener;
  import dtournavigation.android.listeners.OnFragmentListener;
  import dtournavigation.android.model.OTPBundle;
  
  
  public class MyActivity extends FragmentActivity implements OnFragmentListener{
  
      private List&lt;Leg&gt; currentItinerary = new ArrayList&lt;Leg&gt;();
  
      private List&lt;Itinerary&gt; currentItineraryList = new ArrayList&lt;Itinerary&gt;();
  
      private int currentItineraryIndex = -1;
  
      private OTPBundle bundle = null;
  
      private MainFragment mainFragment;
  
      private String TAG = "OTP";
  
      private String currentRequestString="";
  
      private boolean isButtonStartLocation = false;
      DateCompleteListener dateCompleteCallback;
  
      /** Called when the activity is first created. */
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          setContentView(R.layout.splash);
  
          setContentView(R.layout.activity);
  
  
      if (savedInstanceState != null) {
              mainFragment = (MainFragment) getSupportFragmentManager().findFragmentByTag(OTPApp.TAG_FRAGMENT_MAIN_FRAGMENT);//recuperar o tag adecuado e pillar ese fragment
  
          }
  
          if(savedInstanceState==null){
              FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
              mainFragment = new MainFragment();
              fragmentTransaction.replace(R.id.mainFragment, mainFragment, OTPApp.TAG_FRAGMENT_MAIN_FRAGMENT);
              fragmentTransaction.commit();
          }
  
      }
  
      @Override
      protected void onActivityResult(int requestCode, int resultCode, Intent data)
      {
          switch(requestCode) {
          case OTPApp.SETTINGS_REQUEST_CODE: 
              if (resultCode == RESULT_OK) {
                  boolean shouldRefresh = data.getBooleanExtra(OTPApp.REFRESH_SERVER_RETURN_KEY, false);
                  boolean changedSelectedCustomServer = data.getBooleanExtra(OTPApp.CHANGED_SELECTED_CUSTOM_SERVER_RETURN_KEY, false);
                  boolean changedTileProvider = data.getBooleanExtra(OTPApp.CHANGED_MAP_TILE_PROVIDER_RETURN_KEY, false);
  
                  //              Toast.makeText(this, "Should server list refresh? " + shouldRefresh, Toast.LENGTH_LONG).show();
                  if(shouldRefresh){
                      mainFragment.setNeedToRunAutoDetect(true);
                      mainFragment.setNeedToUpdateServersList(true);
                  }
                  if(changedSelectedCustomServer){
                      mainFragment.updateSelectedServer();
                  }
                  if(changedTileProvider){
                      mainFragment.updateOverlay(null);
                  }
                  break;
              }
          case OTPApp.CHOOSE_CONTACT_REQUEST_CODE:
              if(resultCode == RESULT_OK){
  //              Log.v(TAG, "CHOOSE CONTACT RESULT OK");
  
                  Uri contactData = data.getData();
                  Cursor c =  managedQuery(contactData, null, null, null, null);
                  if (c.moveToFirst()) {
                      String address = c.getString(c.getColumnIndexOrThrow(ContactsContract.CommonDataKinds.StructuredPostal.FORMATTED_ADDRESS));
                      mainFragment.setTextBoxLocation(address, isButtonStartLocation);
                      mainFragment.processAddress(isButtonStartLocation, address, false);
                  }
  
                  break;
              }
          }
      }
  
      @Override
      protected void onDestroy() {        
  
          mainFragment = null;
  
          Log.d(TAG, "Released mainFragment with map in MyActivity.onDestroy()");
  
          super.onDestroy();
      }
  
      @Override
      public void onItinerariesLoaded(List&lt;Itinerary&gt; itineraries) {
          // TODO Auto-generated method stub
          currentItineraryList.clear();
          currentItineraryList.addAll(itineraries);
      }
  
      @Override
      public void onItinerarySelected(int i) {
          // TODO Auto-generated method stub
          if(i &gt;= currentItineraryList.size()) return;
  
          currentItineraryIndex = i;
          currentItinerary.clear();
          currentItinerary.addAll(currentItineraryList.get(i).legs);
      }
  
      @Override
      public List&lt;Leg&gt; getCurrentItinerary() {
          // TODO Auto-generated method stub
          return currentItinerary;
      }
  
      @Override
      public void onSwitchedToDirectionFragment() {
          // TODO Auto-generated method stub
          FragmentManager fm = getSupportFragmentManager();
          FragmentTransaction transaction = fm.beginTransaction();
  
          Fragment directionFragment = new DirectionListFragment();
          transaction.add(R.id.mainFragment, directionFragment);
          transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
          transaction.addToBackStack(null);
  
          transaction.commit();
      }
  
      @Override
      public OTPBundle getOTPBundle() {
          // TODO Auto-generated method stub
          return bundle;
      }
  
      @Override
      public void setOTPBundle(OTPBundle b) {
          // TODO Auto-generated method stub
          this.bundle = b;
          this.bundle.setCurrentItineraryIndex(currentItineraryIndex);
          this.bundle.setItineraryList(currentItineraryList);
      }
  
      @Override
      public void onSwitchedToMainFragment(Fragment f) {
          // TODO Auto-generated method stub
          FragmentManager fm = getSupportFragmentManager();
          FragmentTransaction transaction = fm.beginTransaction();
          transaction.remove(f);
          transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
          fm.popBackStack();
          transaction.commit();
  
          mainFragment.showRouteOnMap(currentItinerary, true);
      }
  
      @Override
      public void setCurrentRequestString(String url) {
          currentRequestString = url;
      }
  
      @Override
      public String getCurrentRequestString() {
          return currentRequestString;
      }
  
      @Override
      public void zoomToLocation(LatLng location){
          mainFragment.zoomToLocation(location);
      }
  
      @Override
      public List&lt;Itinerary&gt; getCurrentItineraryList() {
          // TODO Auto-generated method stub
          return currentItineraryList;
      }
  
      @Override
      public int getCurrentItineraryIndex() {
          // TODO Auto-generated method stub
          return currentItineraryIndex;
      }
  
      /**
       * @return the isButtonStartLocation
       */
      public boolean isButtonStartLocation() {
          return isButtonStartLocation;
      }
  
      /**
       * @param isButtonStartLocation the isButtonStartLocation to set
       */
      public void setButtonStartLocation(boolean isButtonStartLocation) {
          this.isButtonStartLocation = isButtonStartLocation;
      }
  
  
      public void setDateCompleteCallback(DateCompleteListener callback){
          this.dateCompleteCallback = callback;
      }
  
      public void onDateComplete(Date tripDate, boolean scheduleType) {
          dateCompleteCallback.onDateComplete(tripDate, scheduleType);
      }
  
  }
  </code></pre>
  
  <p>Mainfragment.java File: for onCreateOptionsMenu.</p>
  
  <pre><code>@Override
      public void onCreateOptionsMenu(Menu pMenu, MenuInflater inflater) {
          // MenuInflater inflater = getMenuInflater();
          super.onCreateOptionsMenu(pMenu, inflater);
          inflater.inflate(R.menu.menu, pMenu);
          mGPS = pMenu.getItem(0);
  
      }   
  
      @Override
      public void onPrepareOptionsMenu(final Menu pMenu) {
          if (isGPSEnabled()) {
              mGPS.setTitle(R.string.disable_gps);
          } else {
              mGPS.setTitle(R.string.enable_gps);
          }
          super.onPrepareOptionsMenu(pMenu);
      }
  
      private Boolean isGPSEnabled() {
      return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
  }
  </code></pre>
  
  <p>Somebody can help me about this problem? Thank You Guys. </p>