title: How to get the ip address with an emulator android
body: <p>Hello
  My aim is to get the local address using the emulator sdk 2.2.
  I wrote this code but when I run it tell me to close the application. 
  this is the code</p>
  
  <pre><code>package exercice1.identificateur.ex;
  
  import java.net.InetAddress;
  import java.net.NetworkInterface;
  import java.net.SocketException;
  import java.util.Enumeration;
  
  import android.app.ListActivity;
  import android.os.Bundle;
  import android.util.Log;
  import android.widget.ArrayAdapter;
  import android.widget.TextView;
  import exercice1.identificateur.R;
  
  public class wifi1 extends ListActivity {
   private static final String LOG_TAG = null;
   public String getLocalIpAddress() {
       try {
           for (Enumeration en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
               NetworkInterface intf = en.nextElement();
               for (Enumeration enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
                   InetAddress inetAddress = enumIpAddr.nextElement();
                   if (!inetAddress.isLoopbackAddress()) {
                       return inetAddress.getHostAddress().toString();
                   }
               }
           }
       } catch (SocketException ex) {
           Log.e(LOG_TAG, ex.toString());
       }
       return null;
   }
  
   public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TextView tv = new TextView(this);
         tv.setText(getLocalIpAddress());
         setContentView(tv);  
   }
  }
  </code></pre>
  
  <p>this is the manifest.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="exercice1.identificateur"
        android:versionCode="1"
        android:versionName="1.0"&gt;
      &lt;application android:icon="@drawable/icon" android:label="@string/app_name"&gt;
          &lt;activity android:name=".ex.wifi1"
                    android:label="@string/app_name"&gt;
              &lt;intent-filter&gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
      &lt;/application&gt;
      &lt;uses-sdk android:minSdkVersion="8" /&gt;
  
  &lt;uses-configuration&gt;&lt;/uses-configuration&gt;
  &lt;uses-feature&gt;&lt;/uses-feature&gt;
  &lt;uses-permission android:name="android.permission.INTERNET"&gt;&lt;/uses-permission&gt;&lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE"&gt;&lt;/uses-permission&gt;&lt;uses-permission android:name="android.permission.CHANGE_WIFI_STATE"&gt;&lt;/uses-permission&gt;&lt;uses-sdk&gt;&lt;/uses-sdk&gt;
  &lt;/manifest&gt; 
  </code></pre>
  
  <p>I hope that you can help me 
  Thank you in advance</p>
  
  <p>(I don't have a device, I use just the emulator installing in my PC. It is possible?) </p>
  
  <p>[edit]
  The error:</p>
  
  <pre><code>12-01 17:13:23.154: ERROR/ AndroidRuntime(511): FATAL EXCEPTION: main
  12-01 17:13:23.154: ERROR/ AndroidRuntime(511): java.lang.RuntimeException: Unable to start activity ComponentInfo{exercice1.identificateur/ exercice1.identificateur.ex.wifi1}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
  </code></pre>