public class MainA extends Activity {
WifiManager wifi=(WifiManager)getSystemService(Context.WIFI_SERVICE);
WifiInfo info=wifi.getConnectionInfo();
String ip;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button bt=(Button)findViewById(R.id.b1);
try{
InetAddress ownIP=InetAddress.getLocalHost();
ip=ownIP.getHostAddress();
//System.out.println("IP of my Android := "+ownIP.getHostAddress());
}catch (Exception e){
//System.out.println("Exception caught ="+e.getMessage());
}
bt.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
// TODO Auto-generated method stub
TextView tv1=(TextView)findViewById(R.id.tv1);
tv1.setText(ip);
}
});
}
}
It stops with the dialog, should I use other method or any other way of using it.I used the getHostAddress() with try- catch, but when I run this it just doesnt run What is wrong in this?