1

jsoup-1.7.1.jar コア ライブラリを使用する Android アプリを開発しようとしています。jar ファイルをライブラリとして含めましたが、使用したいときに毎回 SocketTimeoutException を受け取ります。私は Ubuntu 12.04、eclipse-juno Build id: 20120614-1722、emulator/avd に 100MB の sd、512Ram があり、API レベル 16 に取り組んでいます。

これが私のコードです:

public class MainActivity extends Activity {

private EditText text;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    text = (EditText) findViewById(R.id.editText1);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.mainmenue, menu);
    return true;
}

public void onClick(View view) {

    //Yes I'm aware that this should not be done. I'm planing to use it in the AsyncTask
    //doInBackground method, but since it was not working there, I decided to track it
    //down here in the main-activity -> so it's just for debug
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);


    Document doc = null;
    String url1 = "http://213.165.64.71";
    String url2 = "http://www.google.com";
    try {
        doc = Jsoup.connect(url2).timeout(10*1000).get();
    } catch (SocketTimeoutException a) {
        Log.e("MyAPP", "Exception----------A!", a);
    } catch (Exception e) {
        Log.e("MyAPP", "Exception----------E!", e);
    }
    String title = doc.title();
    Log.i("MyAPP", "Title="+title);
}
}

エラーログ:

10-05 10:45:23.680: E/MyAPP(1433): Exception----------A!
10-05 10:45:23.680: E/MyAPP(1433): java.net.SocketTimeoutException
10-05 10:45:23.680: E/MyAPP(1433):  at java.net.PlainSocketImpl.read(PlainSocketImpl.java:491)
10-05 10:45:23.680: E/MyAPP(1433):  at java.net.PlainSocketImpl.access$000(PlainSocketImpl.java:46)
10-05 10:45:23.680: E/MyAPP(1433):  at java.net.PlainSocketImpl$PlainSocketInputStream.read(PlainSocketImpl.java:240)
10-05 10:45:23.680: E/MyAPP(1433):  at java.io.InputStream.read(InputStream.java:163)
10-05 10:45:23.680: E/MyAPP(1433):  at java.io.BufferedInputStream.fillbuf(BufferedInputStream.java:142)
10-05 10:45:23.680: E/MyAPP(1433):  at java.io.BufferedInputStream.read(BufferedInputStream.java:227)
10-05 10:45:23.680: E/MyAPP(1433):  at libcore.io.Streams.readAsciiLine(Streams.java:201)
10-05 10:45:23.680: E/MyAPP(1433):  at libcore.net.http.ChunkedInputStream.readChunkSize(ChunkedInputStream.java:77)
10-05 10:45:23.680: E/MyAPP(1433):  at libcore.net.http.ChunkedInputStream.read(ChunkedInputStream.java:47)
10-05 10:45:23.680: E/MyAPP(1433):  at java.io.BufferedInputStream.read(BufferedInputStream.java:304)
10-05 10:45:23.680: E/MyAPP(1433):  at java.io.InputStream.read(InputStream.java:163)
10-05 10:45:23.680: E/MyAPP(1433):  at org.jsoup.helper.DataUtil.readToByteBuffer(DataUtil.java:113)
10-05 10:45:23.680: E/MyAPP(1433):  at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:447)
10-05 10:45:23.680: E/MyAPP(1433):  at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:429)
10-05 10:45:23.680: E/MyAPP(1433):  at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:393)
10-05 10:45:23.680: E/MyAPP(1433):  at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:159)
10-05 10:45:23.680: E/MyAPP(1433):  at org.jsoup.helper.HttpConnection.get(HttpConnection.java:148)
10-05 10:45:23.680: E/MyAPP(1433):  at de.funkypopcorn.reggae_a_gwaan.MainActivity.onClick(MainActivity.java:58)
10-05 10:45:23.680: E/MyAPP(1433):  at java.lang.reflect.Method.invokeNative(Native Method)
10-05 10:45:23.680: E/MyAPP(1433):  at java.lang.reflect.Method.invoke(Method.java:511)
10-05 10:45:23.680: E/MyAPP(1433):  at android.view.View$1.onClick(View.java:3586)
10-05 10:45:23.680: E/MyAPP(1433):  at android.view.View.performClick(View.java:4084)
10-05 10:45:23.680: E/MyAPP(1433):  at android.view.View$PerformClick.run(View.java:16966)
10-05 10:45:23.680: E/MyAPP(1433):  at android.os.Handler.handleCallback(Handler.java:615)
10-05 10:45:23.680: E/MyAPP(1433):  at android.os.Handler.dispatchMessage(Handler.java:92)
10-05 10:45:23.680: E/MyAPP(1433):  at android.os.Looper.loop(Looper.java:137)
10-05 10:45:23.680: E/MyAPP(1433):  at android.app.ActivityThread.main(ActivityThread.java:4745)
10-05 10:45:23.680: E/MyAPP(1433):  at java.lang.reflect.Method.invokeNative(Native Method)
10-05 10:45:23.680: E/MyAPP(1433):  at java.lang.reflect.Method.invoke(Method.java:511)
10-05 10:45:23.680: E/MyAPP(1433):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-05 10:45:23.680: E/MyAPP(1433):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-05 10:45:23.680: E/MyAPP(1433):  at dalvik.system.NativeStart.main(Native Method)
10-05 10:45:23.730: E/AndroidRuntime(1433): FATAL EXCEPTION: main
10-05 10:45:23.730: E/AndroidRuntime(1433): java.lang.IllegalStateException: Could not execute method of the activity
10-05 10:45:23.730: E/AndroidRuntime(1433):     at android.view.View$1.onClick(View.java:3591)
10-05 10:45:23.730: E/AndroidRuntime(1433):     at android.view.View.performClick(View.java:4084)
10-05 10:45:23.730: E/AndroidRuntime(1433):     at android.view.View$PerformClick.run(View.java:16966)
10-05 10:45:23.730: E/AndroidRuntime(1433):     at android.os.Handler.handleCallback(Handler.java:615)
10-05 10:45:23.730: E/AndroidRuntime(1433):     at android.os.Handler.dispatchMessage(Handler.java:92)
10-05 10:45:23.730: E/AndroidRuntime(1433):     at android.os.Looper.loop(Looper.java:137)
10-05 10:45:23.730: E/AndroidRuntime(1433):     at android.app.ActivityThread.main(ActivityThread.java:4745)
10-05 10:45:23.730: E/AndroidRuntime(1433):     at java.lang.reflect.Method.invokeNative(Native Method)
10-05 10:45:23.730: E/AndroidRuntime(1433):     at java.lang.reflect.Method.invoke(Method.java:511)
10-05 10:45:23.730: E/AndroidRuntime(1433):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
10-05 10:45:23.730: E/AndroidRuntime(1433):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-05 10:45:23.730: E/AndroidRuntime(1433):     at dalvik.system.NativeStart.main(Native Method)
10-05 10:45:23.730: E/AndroidRuntime(1433): Caused by: java.lang.reflect.InvocationTargetException
10-05 10:45:23.730: E/AndroidRuntime(1433):     at java.lang.reflect.Method.invokeNative(Native Method)
10-05 10:45:23.730: E/AndroidRuntime(1433):     at java.lang.reflect.Method.invoke(Method.java:511)
10-05 10:45:23.730: E/AndroidRuntime(1433):     at android.view.View$1.onClick(View.java:3586)
10-05 10:45:23.730: E/AndroidRuntime(1433):     ... 11 more
10-05 10:45:23.730: E/AndroidRuntime(1433): Caused by: java.lang.NullPointerException
10-05 10:45:23.730: E/AndroidRuntime(1433):     at de.funkypopcorn.reggae_a_gwaan.MainActivity.onClick(MainActivity.java:65)
10-05 10:45:23.730: E/AndroidRuntime(1433):     ... 14 more

はい、さまざまな種類の投稿をすべて検索しましたが、問題の解決策が見つかりませんでした。(これを含む: How to use AsyncTask for Jsoup Parser? )

  • はい、Manifest.xml にインターネット アクセス許可があります (WebView はうまく動作します)
  • プロキシ設定をプロキシなしに変更しました(WebViewも機能する前に、それが原因だとは思いませんが)。
  • 私はさまざまなページで試してみましたが、プレーンIPでも試しました(DNSの問題はありません)

明らかに何かが欠けているのではないでしょうか?本当に感謝します、thx事前に!

Edit1:wiresharkによると、リクエストが送信され、回答が返されます: Wireshark キャップ

Edit2:本当に奇妙です.時々うまくいき、答えが得られます. しかし、3分後にもう一度試してみると、もう機能しません。問題は、10 回に 1 回しか機能しないことです。何か案は?

4

0 に答える 0