私はクラスを使用してAndroidのに問題があるのHttpURLConnection私の方法はこれです:私は、このメソッドのアンドロイドを実行するとHttpURLConnectionの致命的なエラー
public InputStream test() {
URL url = null;
try {
url = new URL("http://www.android.com/");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
HttpURLConnection urlConnection = null;
try {
urlConnection = (HttpURLConnection) url.openConnection();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
InputStream in= null;
try {
in = new BufferedInputStream(urlConnection.getInputStream());
}catch(IOException e){
e.printStackTrace();
}
finally {
urlConnection.disconnect();
}
return in;
}
この例外を生成します。
05-03 15時15: 19.116:W/System.err(1085):android.os.NetworkOnMainThreadException 05-03 15:15:19.116:W/System.err(1085):android.os.StrictMode $ AndroidBlockGuardPolicy.onNetwork(StrictMode.java: 1099) 05-03 15:15:19.116:W/System.err(1085):java.net.InetAddress.lookupHostByName( (InetAddress.java:241) 05-03 15:15:19.116: W/System.err(1085):java.net.InetAddress.getAllByName(InetAddress.java:220) 05-03 15:15:19.126:W/System.err(1085):libcore.net.http。 HttpConnection.java:71 05-03 15:15:19.126:W/System.err(1085):libcore.net.http.HttpConnection。(HttpConnection.java:50) 05-03 15: 15:19.126:W/System.err(1085):libcore.net.http.HttpConnection at Address.connect(HttpConnection.java:351) 05-03 15:15:19.126:W/System.err(1085) :libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86) 05-03 15:15:19.126:W/System.err(1085):libcore.net.http.HttpConnection.connect(HttpConnection。 java:128) 05-03 15:15:19.126:W/System.err(1085):libcore.net.http.HttpEngine.openSocketConnection(HttpEngine.java:308) 05-03 15:15:19.126:W/System。エラー(1085):libcore.net.http.HttpEngine.connect(HttpEngine.java:303) 05-03 15:15:19.126:W/System.err(1085):libcore.net.http.HttpEngine。 sendSocketRequest(HttpEngine.java:282) 05-03 15:15:19.126:W/System.err(1085):libcore.net.http.HttpEngine.sendRequest(HttpEngine.java:232) 05-03 15: 15:19.126:W/System.err(1085):libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:273) 05-03 15:15:19.136:W/System.err(1085):at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168) 05-03 15:15:19.136:W/System.err(1085):com.BertacchiMazzoni.HTTPClient.HttpClientTutorial.tes (HTTPClientActivity.java:18) 05-03 15:15:15:19.136: 15:19.136:W/System.err(1085):android.app.Activity.performCreate(Activity.java:4465) 05-03 15:15:19.136:W/System.err(1085):android。 app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 05-03 15:15:19.136:W/System.err(1085):android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920) 05-03 15:15:19.136:W/System.err(1085):android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981) 05-03 15:15:19.136:W/System.err(1085):at android.app.ActivityThread.access $ 600(ActivityThread.java:123) 05-03 15:15:19.136:W/System.err(1085):androidで.app.ActivityThread $ H.handleMessage(ActivityThread.java:1147) 05-03 15:15:19.146:W/System.err(1085):android.os.Handler.dispatchMessage(Handler.java:99) 05-03 15:15:19.146:W/System.err(1085):android.os.Looper.loop(Looper.java:137) 05-03 15:15:19.146:W/System.err(1085) ):at android.app.ActivityThread.main(ActivityThread.java:4424) 05-03 15:15:19.146:W/System.err(1085):java.lang.reflect.Method.invokeNative(ネイティブメソッド) 05-03 15:15:19.146:W/System.err(1085):java.lang.reflect.Method.invoke(Method.java:511) 05-03 15:15:19.146:W/System。エラー(1085):com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:784) 05-03 15:15:19.146:W/System.err(1085):com.android。 internal.os.ZygoteInit.main(ZygoteInit。Javaの:551) 05-03 15:15:19.146:/をSystem.err(1085)W:dalvik.system.NativeStart.main(ネイティブメソッド)
で私はこの問題を解決することはできますか?エラーはどこですか?
ありがとうございます! よろしく!
manifeastファイルでインターネットにアクセス許可があります... – MAC