title: Changing the content of layout such as text and images before starting the Intent
body: <p>I have 2 views, <code>MainActivity</code> and <code>UnitActivity</code>. In main activity there are some buttons and when user clicks on them I want to bring uo <code>UnitActivity</code>.</p>
  
  <p>In <code>UnitActivity</code> layout file there are some views like TextView. For example, if the user clicks on a button called <code>btn_marine</code> I want to fill the layout with information about marine (a unit in starcraft game, if you know :P).</p>
  
  <p>So my idea is to when user click on button of each unit I fill the text and images of the <code>UnitActivity</code> layout with the information I have about that unit.</p>
  
  <p>At the moment I am trying to hard code this I mean before starting the intent, and I have events for buttons in <code>OnCreate</code> method of <code>MainActivity</code>:</p>
  
  <pre><code>Button btn_marine = (Button) findViewById(R.id.btn_unit_marine);
  btn_marine.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
  
          Intent intent = new Intent(MainActivity.this, UnitActivity.class);
          TextView unitNameView = (TextView) findViewById(R.id.textViewUnitName);
          unitNameView.setText("Marine!"); //this is line 28 with error
          startActivity(intent);
      }
  });
  </code></pre>
  
  <p>But as soon as I click the button application exits with this error in <code>logcat</code>:</p>
  
  <pre><code>07-29 14:56:03.906  12696-12696/com.eetutorials.terranmate E/AndroidRuntime: FATAL EXCEPTION: main
          java.lang.NullPointerException
          at com.eetutorials.terranmate.MainActivity$1.onClick(MainActivity.java:28)
          at android.view.View.performClick(View.java:4204)
          at android.view.View$PerformClick.run(View.java:17355)
          at android.os.Handler.handleCallback(Handler.java:725)
          at android.os.Handler.dispatchMessage(Handler.java:92)
          at android.os.Looper.loop(Looper.java:137)
          at android.app.ActivityThread.main(ActivityThread.java:5041)
          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:793)
          at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
          at dalvik.system.NativeStart.main(Native Method)
  </code></pre>
  
  <p>So my question is what is the problem in my code, and also, what you think is the best way to do such thing? I tried to create a <code>Unit</code> class that holds information about each unit but I dont know how can I fill the Intent from that class.</p>
  
  <p>I mean how can I pass that class to <code>UnitActivity</code> so the views automatically gets populated?</p>
  
  <p>This is for example <code>Unit</code> class I wanted to make:</p>
  
  <pre><code>public class Unit
  {
      private String Name;
      private String HitPoint;
      private String Armor;
      private DamageModifiers DamageModifier;
      private String BaseDamage;
      private String Description;
  
      public String getName() {
          return Name;
      }
  
      public void setName(String name) {
          Name = name;
      }
  
      public String getHitPoint() {
          return HitPoint;
      }
  
      public void setHitPoint(String hitPoint) {
          HitPoint = hitPoint;
      }
  
      public String getArmor() {
          return Armor;
      }
  
      public void setArmor(String armor) {
          Armor = armor;
      }
  
      public DamageModifiers getDamageModifier() {
          return DamageModifier;
      }
  
      public void setDamageModifier(DamageModifiers damageModifier) {
          DamageModifier = damageModifier;
      }
  
      public String getBaseDamage() {
          return BaseDamage;
      }
  
      public void setBaseDamage(String baseDamage) {
          BaseDamage = baseDamage;
      }
  
      public String getDescription() {
          return Description;
      }
  
      public void setDescription(String description) {
          Description = description;
      }
  }
  </code></pre>