我的Android 3.1模擬器出現了一些問題。我無法獲取我的XML文件。Android http連接異常
protected InputStream getInputStream() {
try {
return feedUrl.openConnection().getInputStream();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
這裏的錯誤跟蹤:
08-07 22:34:26.657: ERROR/AndroidRuntime(563): Caused by: android.os.NetworkOnMainThreadException
08-07 22:34:26.657: ERROR/AndroidRuntime(563): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1077)
08-07 22:34:26.657: ERROR/AndroidRuntime(563): at java.net.InetAddress.lookupHostByName(InetAddress.java:477)
08-07 22:34:26.657: ERROR/AndroidRuntime(563): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:277)
08-07 22:34:26.657: ERROR/AndroidRuntime(563): at java.net.InetAddress.getAllByName(InetAddress.java:249)
08-07 22:34:26.657: ERROR/AndroidRuntime(563): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:69)
08-07 22:34:26.657: ERROR/AndroidRuntime(563): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
08-07 22:34:26.657: ERROR/AndroidRuntime(563): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:304)
08-07 22:34:26.657: ERROR/AndroidRuntime(563): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
08-07 22:34:26.657: ERROR/AndroidRuntime(563): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:292)
08-07 22:34:26.657: ERROR/AndroidRuntime(563): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:274)
08-07 22:34:26.657: ERROR/AndroidRuntime(563): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.retrieveResponse(HttpURLConnectionImpl.java:1038)
08-07 22:34:26.657: ERROR/AndroidRuntime(563): at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:523)
08-07 22:34:26.657: ERROR/AndroidRuntime(563): at maps.test.BaseFeedParser.getInputStream(BaseFeedParser.java:30)
08-07 22:34:26.657: ERROR/AndroidRuntime(563): at maps.test.DomFeedParser.parse(DomFeedParser.java:23)
我想我無法連接到互聯網,甚至<uses-permission android:name="android.permission.INTERNET"/>
。但在同一時間,谷歌API工作得很好。
的[android.os.NetworkOnMainThreadException(可能重複http://stackoverflow.com/questions/6343166/android -os-networkonmainthreadexception) – laalto