httpgetをリクエストして文字列に変換してテキストビューに入れるアンドロイドアプリケーションを開発していますが、エミュレータとAndroidデバイスの迷惑なエラーですそれは次のとおりです。HttpGetを使用すると、UnknownHostExceptionが発生する
01-26 05:08:25.346: D/AndroidRuntime(523): Shutting down VM
01-26 05:08:25.346: W/dalvikvm(523): threadid=1: thread exiting with uncaught exception (group=0x40015560)
01-26 05:08:25.366: E/AndroidRuntime(523): FATAL EXCEPTION: main
01-26 05:08:25.366: E/AndroidRuntime(523): java.lang.IllegalStateException: Could not execute method of the activity
01-26 05:08:25.366: E/AndroidRuntime(523): at android.view.View$1.onClick(View.java:2144)
01-26 05:08:25.366: E/AndroidRuntime(523): at android.view.View.performClick(View.java:2485)
01-26 05:08:25.366: E/AndroidRuntime(523): at android.view.View$PerformClick.run(View.java:9080)
01-26 05:08:25.366: E/AndroidRuntime(523): at android.os.Handler.handleCallback(Handler.java:587)
01-26 05:08:25.366: E/AndroidRuntime(523): at android.os.Handler.dispatchMessage(Handler.java:92)
01-26 05:08:25.366: E/AndroidRuntime(523): at android.os.Looper.loop(Looper.java:123)
01-26 05:08:25.366: E/AndroidRuntime(523): at android.app.ActivityThread.main(ActivityThread.java:3683)
01-26 05:08:25.366: E/AndroidRuntime(523): at java.lang.reflect.Method.invokeNative(Native Method)
01-26 05:08:25.366: E/AndroidRuntime(523): at java.lang.reflect.Method.invoke(Method.java:507)
01-26 05:08:25.366: E/AndroidRuntime(523): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
01-26 05:08:25.366: E/AndroidRuntime(523): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
01-26 05:08:25.366: E/AndroidRuntime(523): at dalvik.system.NativeStart.main(Native Method)
01-26 05:08:25.366: E/AndroidRuntime(523): Caused by: java.lang.reflect.InvocationTargetException
01-26 05:08:25.366: E/AndroidRuntime(523): at java.lang.reflect.Method.invokeNative(Native Method)
01-26 05:08:25.366: E/AndroidRuntime(523): at java.lang.reflect.Method.invoke(Method.java:507)
01-26 05:08:25.366: E/AndroidRuntime(523): at android.view.View$1.onClick(View.java:2139)
01-26 05:08:25.366: E/AndroidRuntime(523): ... 11 more
01-26 05:08:25.366: E/AndroidRuntime(523): Caused by: java.net.UnknownHostException: www.conecciones.net
01-26 05:08:25.366: E/AndroidRuntime(523): at java.net.InetAddress.lookupHostByName(InetAddress.java:506)
01-26 05:08:25.366: E/AndroidRuntime(523): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:294)
01-26 05:08:25.366: E/AndroidRuntime(523): at java.net.InetAddress.getAllByName(InetAddress.java:256)
01-26 05:08:25.366: E/AndroidRuntime(523): at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:136)
01-26 05:08:25.366: E/AndroidRuntime(523): at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
01-26 05:08:25.366: E/AndroidRuntime(523): at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
01-26 05:08:25.366: E/AndroidRuntime(523): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:359)
01-26 05:08:25.366: E/AndroidRuntime(523): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
01-26 05:08:25.366: E/AndroidRuntime(523): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
01-26 05:08:25.366: E/AndroidRuntime(523): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
01-26 05:08:25.366: E/AndroidRuntime(523): at sys.temperature.ConvertActivity.executeHttpGet(ConvertActivity.java:82)
01-26 05:08:25.366: E/AndroidRuntime(523): at sys.temperature.ConvertActivity.myClickHandler(ConvertActivity.java:70)
01-26 05:08:25.366: E/AndroidRuntime(523): ... 14 more
01-26 05:08:29.187: I/Process(523): Sending signal. PID: 523 SIG: 9
そしてここでは私のコードです:
public void executeHttpGet(String cis) throws Exception {
BufferedReader in = null;
try {
HttpClient client = new DefaultHttpClient();
Toast.makeText(this, "http://www.**************.net/******/test.php?ci=" + cis, 2).show();
HttpGet request = new HttpGet(http://www.**************.net/******/test.php?ci=" + cis);
//request.setURI(new URI("http://w3mentor.com/"));
HttpResponse response = client.execute(request);
in = new BufferedReader
(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
in.close();
String page = sb.toString();
System.out.println(page);
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
間違って何イム? ありがとう、素敵な一日を!
これは魅力的に機能しました!本当にありがとう! –
私の答えはAcceptedとしてマークすることを忘れないでください。それはあなたのために働く場合。ありがとう – Arslan