How to get the ip address with an emulator android -
hello aim local address using emulator sdk 2.2. wrote code when run tell me close application. 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 { (enumeration en = networkinterface.getnetworkinterfaces(); en.hasmoreelements();) { networkinterface intf = en.nextelement(); (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); } }
this manifest.xml
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="exercice1.identificateur" android:versioncode="1" android:versionname="1.0"> <application android:icon="@drawable/icon" android:label="@string/app_name"> <activity android:name=".ex.wifi1" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> <uses-sdk android:minsdkversion="8" /> <uses-configuration></uses-configuration> <uses-feature></uses-feature> <uses-permission android:name="android.permission.internet"></uses-permission><uses-permission android:name="android.permission.access_wifi_state"></uses-permission><uses-permission android:name="android.permission.change_wifi_state"></uses-permission><uses-sdk></uses-sdk> </manifest>
i hope can me thank in advance
(i don't have device, use emulator installing in pc. possible?)
[edit] error:
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 start activity componentinfo{exercice1.identificateur/ exercice1.identificateur.ex.wifi1}: java.lang.runtimeexception: content must have listview id attribute 'android.r.id.list'
very question warrenfaith. looks dalvikvm looking precompiled or generated class (ex.nomprenom). what's project structure? these files in project?
i think link in 1 of r files of package.
Comments
Post a Comment