2010-12-01 21 views
0

こんにちは 私の目的は、エミュレータsdk 2.2を使用してローカルアドレスを取得することです。 私はこのコードを書いたが、実行するとアプリケーションを終了するように指示する。 これはコードエミュレータでipアドレスを取得する方法android

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); 
} 
} 

これは、私は(私はデバイスを持っていないあなたは 事前

にありがとう私を助けることができることを願っての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> 

です私は自分のPCにインストールされているエミュレータだけを使用することができますか?)

[編集] エラー:

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' 
+1

あなたのクラス 'exerciseice1.identificateur.ex.nomprenom'はどこですか? – WarrenFaith

答えて

0

非常に良い質問WarrenFaith。私はDalvikVMがプリコンパイルされたクラス(ex.nomprenom)を探しているようです。あなたのプロジェクトの構造は何ですか?これらすべてのファイルはプロジェクトにありますか?

あなたのパッケージのRファイルの1つにリンクされていると思います。

+0

私のクラスの名前をnomprenomからwifi1に変更しました。 –

+0

それは問題です。名前の変更が完全に行われていないように見えます。プロジェクトをきれいにして、エミュレータからアプリケーションを削除して、再度展開してください。 – WarrenFaith

+0

同じ問題。私はlogcatをmartinにします。私はここに投稿することはできません –

関連する問題