代码改变世界

java.net.UnknownHostException: XXX.XXX Android

2012-01-29 21:56  轩脉刃  阅读(3942)  评论(1编辑  收藏  举报

android开发

 

OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());

 

这步的时候抛出异常:

java.net.UnknownHostException: api.kaixin001.com

 

解决方法:

http://eliasbland.wordpress.com/2011/02/22/java-net-unknownhostexception-on-android-a-list-of-possible-causes/

 

在AndroidManifest.xml中增加这么一句:

<uses-permission android:name="android.permission.INTERNET" />

 

如下:

<application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".RecordActivity"
                  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-permission android:name="android.permission.INTERNET" />

 

ok