title: Unable to start actvity componentinfo - android app barcode scanner
body: <p>I am trying to implement a scanner to read in code and later use it in my application to show and filter data. Code snippet is below for the app, taken from a tutorial online. </p>
  
  <p>I am getting the below error when I try to run the app</p>
  
  <pre><code>    **FATAL EXCEPTION: main
  Process: com.example.barcodescanningapp, PID: 27516
  java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.barcodescanningapp/com.example.barcodescanningapp.MainActivity}: java.lang.NullPointerException
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
  at android.app.ActivityThread.access$800(ActivityThread.java:135)
  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
  at android.os.Handler.dispatchMessage(Handler.java:102)
  at android.os.Looper.loop(Looper.java:136)
  at android.app.ActivityThread.main(ActivityThread.java:5001)
  at java.lang.reflect.Method.invokeNative(Native Method)
  at java.lang.reflect.Method.invoke(Method.java:515)
  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
  at dalvik.system.NativeStart.main(Native Method)
  E/AndroidRuntime(27516): Caused by: java.lang.NullPointerException
  at com.example.barcodescanningapp.MainActivity.onCreate(MainActivity.java:38)
  at android.app.Activity.performCreate(Activity.java:5231)
  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)**
  </code></pre>
  
  <p>I am not able to identify from where my null point exception is from. Please help.</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity implements OnClickListener{
  private Button scanBtn;
  private TextView formatTxt, contentTxt;
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      if (savedInstanceState == null) {
          getSupportFragmentManager().beginTransaction()
                  .add(R.id.container, new PlaceholderFragment()).commit();
      }
      scanBtn = (Button)findViewById(R.id.scan_button);
      formatTxt = (TextView)findViewById(R.id.scan_format);
      contentTxt = (TextView)findViewById(R.id.scan_content);
      scanBtn.setOnClickListener(this);
  }
  
  public void onClick(View v){
      //respond to clicks
      if(v.getId()==R.id.scan_button){
          //scan
          IntentIntegrator scanIntegrator = new IntentIntegrator(this);
          scanIntegrator.initiateScan();
          }
  
      }
  
  public void onActivityResult(int requestCode, int resultCode, Intent intent) {
      //retrieve scan result
      IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
      if (scanningResult != null) {
          //we have a result
          String scanContent = scanningResult.getContents();
          String scanFormat = scanningResult.getFormatName();
          formatTxt.setText("FORMAT: " + scanFormat);
          contentTxt.setText("CONTENT: " + scanContent);
          }
      else{
          Toast toast = Toast.makeText(getApplicationContext(), 
              "No scan data received!", Toast.LENGTH_SHORT);
          toast.show();
      }
  
  }
  
  
  @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, menu);
      return true;
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
      // Handle action bar item clicks here. The action bar will
      // automatically handle clicks on the Home/Up button, so long
      // as you specify a parent activity in AndroidManifest.xml.
      int id = item.getItemId();
      if (id == R.id.action_settings) {
          return true;
      }
      return super.onOptionsItemSelected(item);
  }
  
  /**
   * A placeholder fragment containing a simple view.
   */
  public static class PlaceholderFragment extends Fragment {
  
      public PlaceholderFragment() {
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          View rootView = inflater.inflate(R.layout.fragment_main, container,
                  false);
          return rootView;
      }
  }
  }   
  </code></pre>