0

次のコードを見てください

TT.Java

public class TT extends Activity{

private EditText textField;

    private boolean isSpeaking = false;

    private AudioManager audioManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_talk);


        textField = (EditText)findViewById(R.id.textField);
        if (Intent.ACTION_SEND.equals(getIntent().getAction())) 
    {
        String text = getIntent().getStringExtra(Intent.EXTRA_TEXT);
        Document doc;

         try {
              doc = Jsoup.connect("http://docs.opencv.org/doc/tutorials/introduction/windows_install/windows_install.html#windows-installation").get();
              Elements paragraphs = doc.select("p");
              for(Element p : paragraphs)
              {
                //System.out.println(p.text());
                textField.setText(p.text());
              }
            } 
            catch (IOException ex)
            {
                textField.setText(ex.getLocalizedMessage());
                Toast.makeText(this, ex.getLocalizedMessage(), Toast.LENGTH_LONG).show();

            } 


    }
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.talk, menu);
        return true;
    }

    }

このクラスは、Android Web ブラウザーの [Share-Via] ボタンをクリックし、このプログラムを選択すると呼び出すことができます。このクラスの目的は、共有 Web ページ (任意のページ) からテキスト (テキストのみ) を抽出し、この に表示することEditTextです。残念ながら、これは私に何の出力も与えませんでした。代わりにIOException、URL を生成して出力します。

IOException私は今まで見たことのないものを手に入れました。私が得る例外は

doc.opencv.org

部分は、このJSoupスレッドの選択された回答から抽出されます - How to extract text of text from html using Jsoup? . その場合、SOメンバーはそれが機能していると言っています!

以下は、このクラスをShare-Via

Androidマニフェスト

<activity
        android:name="com.xxx.xxx.TT"
        android:screenOrientation="portrait"
        android:label="@string/app_name" >

        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="text/plain"/>
        </intent-filter>

    </activity>

以下は完全なスタックトレースです

10-09 13:45:18.244: I/TextToSpeech.java(1325): initTts() successfully bound to service
10-09 13:45:18.464: E/IOException_Share(1325): IOException in share
10-09 13:45:18.464: E/IOException_Share(1325): java.net.UnknownHostException: docs.opencv.org
10-09 13:45:18.464: E/IOException_Share(1325):  at java.net.InetAddress.lookupHostByName(InetAddress.java:506)
10-09 13:45:18.464: E/IOException_Share(1325):  at java.net.InetAddress.getAllByNameImpl(InetAddress.java:294)
10-09 13:45:18.464: E/IOException_Share(1325):  at java.net.InetAddress.getAllByName(InetAddress.java:256)
10-09 13:45:18.464: E/IOException_Share(1325):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:69)
10-09 13:45:18.464: E/IOException_Share(1325):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java:48)
10-09 13:45:18.464: E/IOException_Share(1325):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection$Address.connect(HttpConnection.java:322)
10-09 13:45:18.464: E/IOException_Share(1325):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java:89)
10-09 13:45:18.464: E/IOException_Share(1325):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHttpConnection(HttpURLConnectionImpl.java:285)
10-09 13:45:18.464: E/IOException_Share(1325):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.makeConnection(HttpURLConnectionImpl.java:267)
10-09 13:45:18.464: E/IOException_Share(1325):  at org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:205)
10-09 13:45:18.464: E/IOException_Share(1325):  at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:425)
10-09 13:45:18.464: E/IOException_Share(1325):  at org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:410)
10-09 13:45:18.464: E/IOException_Share(1325):  at org.jsoup.helper.HttpConnection.execute(HttpConnection.java:164)
10-09 13:45:18.464: E/IOException_Share(1325):  at org.jsoup.helper.HttpConnection.get(HttpConnection.java:153)
10-09 13:45:18.464: E/IOException_Share(1325):  at com.xxx.xxx.TT.onCreate(Talk.java:71)
10-09 13:45:18.464: E/IOException_Share(1325):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
10-09 13:45:18.464: E/IOException_Share(1325):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
10-09 13:45:18.464: E/IOException_Share(1325):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
10-09 13:45:18.464: E/IOException_Share(1325):  at android.app.ActivityThread.access$1500(ActivityThread.java:117)
10-09 13:45:18.464: E/IOException_Share(1325):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
10-09 13:45:18.464: E/IOException_Share(1325):  at android.os.Handler.dispatchMessage(Handler.java:99)
10-09 13:45:18.464: E/IOException_Share(1325):  at android.os.Looper.loop(Looper.java:123)
10-09 13:45:18.464: E/IOException_Share(1325):  at android.app.ActivityThread.main(ActivityThread.java:3683)
10-09 13:45:18.464: E/IOException_Share(1325):  at java.lang.reflect.Method.invokeNative(Native Method)
10-09 13:45:18.464: E/IOException_Share(1325):  at java.lang.reflect.Method.invoke(Method.java:507)
10-09 13:45:18.464: E/IOException_Share(1325):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-09 13:45:18.464: E/IOException_Share(1325):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-09 13:45:18.464: E/IOException_Share(1325):  at dalvik.system.NativeStart.main(Native Method)

ここでライブラリを使用JSoupしましたが、経験はありません。継続的に が表示されるのはなぜIOExceptionですか? 私は何を間違っていますか?

4

1 に答える 1