title: Android - SensorEventListenr in a Fragment
body: <p>I am trying to add a sensoreventlistener to a fragment in my app.</p>
  
  <p>Below is the code I am using to define the Sensor</p>
  
  <pre><code>Context context;
  
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
          Bundle savedInstanceState) {
      // TODO Auto-generated method stub
  
      mLinearLayout = (LinearLayout) inflater.inflate(
              R.layout.game, container, false);
          this.context = context;
  
           mSensorManager = (SensorManager)context.getSystemService(Context.SENSOR_SERVICE);
  //above is line 49 which is referenced in the logcat
           mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
  
  //...
  return mLinearLayout;
  }
  </code></pre>
  
  <p>And here is the logcat error</p>
  
  <pre><code>07-27 00:19:50.907: E/AndroidRuntime(20595): FATAL EXCEPTION: main
  07-27 00:19:50.907: E/AndroidRuntime(20595): java.lang.NullPointerException
  07-27 00:19:50.907: E/AndroidRuntime(20595):    at com.Optimus.iwould.Game.onCreateView(Game.java:49)
  07-27 00:19:50.907: E/AndroidRuntime(20595):    at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478)
  07-27 00:19:50.907: E/AndroidRuntime(20595):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927)
  </code></pre>
  
  <p>Thanks</p>