1. ホーム
  2. android

[解決済み] オペレーションタイムアウト

2022-02-01 22:11:16

質問事項

この奇妙なエラーが発生しました。私はそれを解決しようとして無制限のタイムアウトを置くことさえあった。以前はうまくいっていたのに、今はうまくいかず、理由がわからないからです。エラーは

09-05 22:40:04.930: W/IInputConnectionWrapper(820): showStatusIcon on inactive InputConnection
09-05 22:43:26.901: E/ServicioRest(881): Error en listar!
09-05 22:43:26.901: E/ServicioRest(881): java.net.SocketException: The operation timed out
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.harmony.luni.platform.OSNetworkSystem.connectStreamWithTimeoutSocketImpl(Native Method)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.harmony.luni.platform.OSNetworkSystem.connect(OSNetworkSystem.java:115)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:244)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.harmony.luni.net.PlainSocketImpl.connect(PlainSocketImpl.java:533)
09-05 22:43:26.901: E/ServicioRest(881):    at java.net.Socket.connect(Socket.java:1055)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:119)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:143)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:348)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
09-05 22:43:26.901: E/ServicioRest(881):    at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
09-05 22:43:26.901: E/ServicioRest(881):    at com.example.interviewhelpers.ClientDetailActivity.onCreateView(ClientDetailActivity.java:72)
09-05 22:43:26.901: E/ServicioRest(881):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:870)
09-05 22:43:26.901: E/ServicioRest(881):    at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1080)
09-05 22:43:26.901: E/ServicioRest(881):    at android.support.v4.app.BackStackRecord.run(BackStackRecord.java:622)
09-05 22:43:26.901: E/ServicioRest(881):    at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1416)
09-05 22:43:26.901: E/ServicioRest(881):    at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:505)
09-05 22:43:26.901: E/ServicioRest(881):    at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1129)
09-05 22:43:26.901: E/ServicioRest(881):    at android.app.Activity.performStart(Activity.java:3781)
09-05 22:43:26.901: E/ServicioRest(881):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2636)
09-05 22:43:26.901: E/ServicioRest(881):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-05 22:43:26.901: E/ServicioRest(881):    at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-05 22:43:26.901: E/ServicioRest(881):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-05 22:43:26.901: E/ServicioRest(881):    at android.os.Handler.dispatchMessage(Handler.java:99)
09-05 22:43:26.901: E/ServicioRest(881):    at android.os.Looper.loop(Looper.java:123)
09-05 22:43:26.901: E/ServicioRest(881):    at android.app.ActivityThread.main(ActivityThread.java:4627)
09-05 22:43:26.901: E/ServicioRest(881):    at java.lang.reflect.Method.invokeNative(Native Method)
09-05 22:43:26.901: E/ServicioRest(881):    at java.lang.reflect.Method.invoke(Method.java:521)
09-05 22:43:26.901: E/ServicioRest(881):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-05 22:43:26.901: E/ServicioRest(881):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-05 22:43:26.901: E/ServicioRest(881):    at dalvik.system.NativeStart.main(Native Method)

これは、ウェブサービスを呼び出すメソッドです。最後の行は、eclipseが問題発生を教えてくれたところです。

public static final String ruta = "http://10.0.0.2:2731/Api/Usuario";

        HttpParams httpParameters = new BasicHttpParams();
        HttpConnectionParams.setConnectionTimeout(httpParameters, 0);
        HttpConnectionParams.setSoTimeout(httpParameters, 0);
        HttpConnectionParams.setTcpNoDelay(httpParameters, true);

        HttpClient httpClient = new DefaultHttpClient(httpParameters);
        HttpGet del = new HttpGet(ruta + "s");
        del.setHeader("content-type", "application/json");

        try {
            HttpResponse resp = httpClient.execute(del);

解決方法は?

あなたのコードでは、タイムアウトの値を0としていました。0の代わりに、5000(ミリ秒)以上の値を使用してください。 つまり、HttpConnectionParams.setConnectionTimeout(httpParameters, 5000)です。 HttpConnectionParams.setSoTimeout(httpParameters, 5000)。