title: How to Dynamically set text to TextView?
body: <p>I want to display the connected ssid and ip address when the activity starts. It contais an image view (for title, because i'm not using the action bar) and 4 text view (ssid label, ssid value, ipaddr label, and ipaddr value)</p>
  
  <p>I've tested the codes for obtaining the ssid and the ipaddr and they worked well. The problem is I can't display them into the TextView.</p>
  
  <p>In this code, there is no error, but when the activity start, the program crash, or stop working.</p>
  
  <p>Here is my java code:</p>
  
  <pre><code>import android.app.Activity;
  import android.net.wifi.WifiInfo;
  import android.net.wifi.WifiManager;
  import android.os.Bundle;
  
  public class ConnectionInfoActivity extends Activity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      TextView ssid = (TextView) findViewById (R.id.ssid);
      TextView ip = (TextView) findViewById (R.id.ipaddr);
  
      ssid.setText(getSsid());
      ip.setText(getIpAddr());
  
      setContentView(R.layout.activity_connection_info);
  }   
  
  // Get the connected network SSID
  private String getSsid() {
      WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
      WifiInfo wifiInfo = wifiManager.getConnectionInfo();
      String ssid = null;
  
      ssid = wifiInfo.getSSID();
  
      return ssid;
  }
  
  // Get the network IP Address
  private String getIpAddr() {
      WifiManager wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
      WifiInfo wifiInfo = wifiManager.getConnectionInfo();
      int ip = wifiInfo.getIpAddress();
  
      String ipString = null;
      ipString = String.format(
          "%d.%d.%d.%d",
          (ip &amp; 0xff),
          (ip &gt;&gt; 8 &amp; 0xff),
          (ip &gt;&gt; 16 &amp; 0xff),
          (ip &gt;&gt; 24 &amp; 0xff));
  
      return ipString;
      }
  }
  </code></pre>
  
  <p>And the layout xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/coninfo_container"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@drawable/background"
      android:orientation="vertical" &gt;
  
  &lt;ImageView
      android:id="@+id/title_conInfo"
      android:layout_width="fill_parent"
      android:layout_height="44.5dp"
      android:src="@drawable/header_coninfo" /&gt;
  
  &lt;TableLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content"&gt;
  
      &lt;TableRow&gt;
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:padding="10dp"
              android:textSize="20sp"
              android:text="SSID" /&gt;
          &lt;TextView
              android:id="@+id/ssid"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:padding="10dp"
              android:textSize="20sp"
              android:text="" /&gt;
      &lt;/TableRow&gt;
  
      &lt;TableRow&gt;
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:padding="10dp"
              android:textSize="20sp"
              android:text="IP Address" /&gt;
          &lt;TextView
              android:id="@+id/ipaddr"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:padding="10dp"
              android:textSize="20sp"
              android:text="" /&gt;
      &lt;/TableRow&gt;
  &lt;/TableLayout&gt;
  </code></pre>
  
  <p></p>