Я пытаюсь прочитать файл из Интернета с помощью httpclient и получаю эту ошибку. Что я делаю неправильно? Пример кода будет оценен.
11-02 17:21:09.845: WARN/ActivityManager(67): Launch timeout has expired, giving up wake lock!
11-02 17:21:10.464: WARN/ActivityManager(67): Activity idle timeout for HistoryRecord{405591c0 com.jeffbreunig/.RetrievingAmazonXMLDataActivity}
11-02 17:21:15.534: DEBUG/dalvikvm(310): GC_EXPLICIT freed 7K, 54% free 2537K/5511K, external 1625K/2137K, paused 64ms
11-02 17:21:18.244: DEBUG/SntpClient(67): request time failed: java.net.SocketException: Address family not supported by protocol
11-02 17:21:20.998: DEBUG/(1879): DID NOT WORK
11-02 17:21:21.344: INFO/ActivityManager(67): Displayed com.jeffbreunig/.RetrievingAmazonXMLDataActivity: +21s38ms
код:
public class RetrievingAmazonXMLDataActivity extends Activity {
private static final String TAG = null;
TextView txt;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txt = (TextView) findViewById(R.id.txt);
String urlToRead = "http://webdev4.matcmadison.edu/mbtest/mab/AmazonXML/FileList.txt";
try {
String fileList = getContent(urlToRead);
txt.setText(fileList);
} catch (Exception e) {
Log.println(Log.DEBUG, TAG, "DUMP FILES DID NOT WORK");
}
}
public String getContent(String url) {
String responseBody;
try {
HttpClient client = new DefaultHttpClient();
ResponseHandler<String> responseHandler = new BasicResponseHandler();
HttpGet getMethod = new HttpGet(url);
responseBody = client.execute(getMethod, responseHandler);
}
catch (Exception ex) {
Log.println(Log.DEBUG, TAG,"DID NOT WORK");
Toast.makeText(this, "Request failed: " + ex.getMessage(), 6000).show();
return "Failure to read from server!";
}
return responseBody;
}
public void onItemSelected(AdapterView<?> parent, View v, int position, long id)
{
String s = String.format("You chose [%s]", items[position]);
}
public void onNothingSelected(AdapterView<?>parent) {
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.jeffbreunig"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="9" />
<uses-permission android:name="android.permission.INTERNET"/>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".RetrievingAmazonXMLDataActivity"
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>
</manifest>