title: Display Strings from an arrayList in android
body: <p>Currently I have two activity's in my android up. The MainActivity page displays toast notifications and I want my HistoryActivity page to display all the previous toasts. Before I send a toast from my MainActivity page I save into arrayList. Then, I want to display all the strings in this arrayList on the HistoryActivity page. I am unsure how to build a textview and how to integrate the textview with the strings in the arrayList. Please Help.</p>
  
  <p>I also think I need to add something to my xml files, but I'm unsure of that too. Thanks.</p>
  
  <p>The current code looks like this for the MainActivity page.</p>
  
  <pre><code>import java.util.ArrayList;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.os.Bundle;
  import android.util.Log;
  import android.view.Menu;
  import android.view.View;
  import android.widget.Toast;
  
  
  public class MainActivity extends Activity {
  private ContextCoreConnector contextCoreConnector;
  private ContextPlaceConnector contextPlaceConnector;
  private ArrayList&lt;String&gt; locations;
  
  //Initializing contextPlaceConnector here, I initialize PlaceEventListener below and the logic for when a geofence is broken is below.
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
  
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      contextCoreConnector = ContextCoreConnectorFactory.get(this);
      contextPlaceConnector = ContextPlaceConnectorFactory.get(this);
  
      checkContextConnectorStatus();
  }
  
  
  @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;
  }
  
  private PlaceEventListener placeEventListener = new PlaceEventListener() {
  
      @Override
      public void placeEvent(PlaceEvent event) {
          String placeNameAndIdCurrent = " You are now at " + event.getPlace().getPlaceName() + ". The ID number of this location is " + event.getPlace().getId();
          String placeNameId = "Location is "+event.getPlace().getPlaceName() +". The ID number of this location is " + event.getPlace().getId();
          Toast toast = Toast.makeText(getApplicationContext(), placeNameAndIdCurrent, Toast.LENGTH_LONG);//changed from Toast.LENGTH_LONG
          toast.show();
          Log.i("found place", placeNameAndIdCurrent);
          locations= new ArrayList&lt;String&gt;();
          locations.add(placeNameId);
      }
  };
  
  private void checkContextConnectorStatus() {
      if (contextCoreConnector.isPermissionEnabled()) {
          // Gimbal is already enabled
          startListeningForGeofences();
      }
      else {
          contextCoreConnector.enable(this, new Callback&lt;Void&gt;() {
  
              @Override
              public void success(Void arg0) {
                  startListeningForGeofences();
                  // Gimbal is ready
              }
  
              @Override
              public void failure(int arg0, String arg1) {
                  Log.e("failed to enable", arg1);
              }
          });
      }
  }
  private void startListeningForGeofences() {
      contextPlaceConnector.addPlaceEventListener(placeEventListener);
  }
  @Override
  protected void onResume() {
  super.onResume(); 
  contextCoreConnector.setCurrentActivity(this);
  }
  @Override
  protected void onPause() {
  super.onPause(); contextCoreConnector.setCurrentActivity(null);
  }
  
  public void sendHistory(View view){
      Intent intent = new Intent(this, HistoryActivity.class);
      //EditText editText = (EditText) findViewById(R.id.edit_message);
      intent.putStringArrayListExtra("key", locations);
      startActivity(intent);  
  }
  public void sendLogin(View view){
      Intent intent = new Intent(this, LoginActivity.class);
      //EditText editText = (EditText) findViewById(R.id.edit_message);
      startActivity(intent);  
  }
  
  // return arrayList so that it can be used in other classes
  public ArrayList&lt;String&gt; getList(){
      return locations;
  }
  </code></pre>
  
  <p>Then the HistoryActivity page looks like this.</p>
  
  <pre><code>import java.util.ArrayList;
  
  import android.app.Activity;
  import android.os.Bundle;
  import android.view.Menu;
  import android.widget.LinearLayout;
  import android.widget.TextView;
  
  
  public class HistoryActivity extends Activity {
  //private MainActivity Mac;
  private TextView myText = null;
  ArrayList&lt;String&gt; list = getIntent().getStringArrayListExtra("key");
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_history);
  
      LinearLayout lView = new LinearLayout(this);
  
          myText= new TextView(this);
          lView.addView(myText);
          for (int i=0; i&lt;list.size();i++){
              myText.append(list.get(i));
              myText.append("\n");
          }
      setContentView(lView);
  
  
  }
  
  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
      // Inflate the menu; this adds items to the action bar if it is present.
      getMenuInflater().inflate(R.menu.history, menu);
      return true;
  }
  </code></pre>
  
  <p>Now I am getting this error.</p>
  
  <pre><code>01-31 01:28:25.675: E/AndroidRuntime(14623): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{concertpass.app/concertpass.app.HistoryActivity}: java.lang.NullPointerException
  01-31 01:28:25.675: E/AndroidRuntime(14623):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2585)
  01-31 01:28:25.675: E/AndroidRuntime(14623):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
  01-31 01:28:25.675: E/AndroidRuntime(14623):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
  01-31 01:28:25.675: E/AndroidRuntime(14623):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
  01-31 01:28:25.675: E/AndroidRuntime(14623):    at android.os.Handler.dispatchMessage(Handler.java:99)
  01-31 01:28:25.675: E/AndroidRuntime(14623):    at android.os.Looper.loop(Looper.java:123)
  01-31 01:28:25.675: E/AndroidRuntime(14623):    at android.app.ActivityThread.main(ActivityThread.java:4627)
  01-31 01:28:25.675: E/AndroidRuntime(14623):    at java.lang.reflect.Method.invokeNative(Native Method)
  01-31 01:28:25.675: E/AndroidRuntime(14623):    at java.lang.reflect.Method.invoke(Method.java:521)
  01-31 01:28:25.675: E/AndroidRuntime(14623):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
  01-31 01:28:25.675: E/AndroidRuntime(14623):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
  01-31 01:28:25.675: E/AndroidRuntime(14623):    at dalvik.system.NativeStart.main(Native Method)
  01-31 01:28:25.675: E/AndroidRuntime(14623): Caused by: java.lang.NullPointerException
  01-31 01:28:25.675: E/AndroidRuntime(14623):    at concertpass.app.HistoryActivity.&lt;init&gt;(HistoryActivity.java:15)
  01-31 01:28:25.675: E/AndroidRuntime(14623):    at java.lang.Class.newInstanceImpl(Native Method)
  01-31 01:28:25.675: E/AndroidRuntime(14623):    at java.lang.Class.newInstance(Class.java:1429)
  01-31 01:28:25.675: E/AndroidRuntime(14623):    at android.app.Instrumentation.newActivity(Instrumentation.java:1023)
  01-31 01:28:25.675: E/AndroidRuntime(14623):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2577)
  
  &lt;activity
      android:name="concertpass.app.HistoryActivity"
      android:label="@string/title_activity_history" &gt;
  &lt;/activity&gt;
  </code></pre>
  
  <p>Thanks again.</p>