다음 코드에서 참조하시기 바랍니다항상 IOException이 발생합니다.
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;
}
}
이 클래스는 당신이 당신의 안드로이드 웹 브라우저의 "공유-통해"버튼을 클릭하고이를 선택할 때 호출 할 수 있습니다 프로그램. 이 클래스의 목적은 공유 웹 페이지 (모든 페이지)에서 텍스트 (텍스트 만)를 추출하여 EditText
에 표시하는 것입니다. 불행히도, 이것은 나에게 어떤 결과도주지 못했습니다. 대신 IOException
을 생성하고 URL을 인쇄합니다.
IOException
나는 매우 이상합니다. 전에 본 적이 없습니다. 내가 얻을 예외는 JSoup
부분이 스레드의 선택한 답변에서 추출
doc.opencv.org
입니다 - How to extract text of paragraph from html using Jsoup?. 그 경우, SO 회원은 그것이 일하고 있다고 말한다!
에 따라 내가 Share-Via
AndroidManifest를이 클래스를 추가하는 방법입니다 아래
<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>
내가
JSoup
라이브러리 여기에 사용했다
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)
전체 스택 트레이스 없지만 나는 더이 그것의 경험. 지속적으로 IOException
을받는 이유는 무엇입니까? 내가 도대체 뭘 잘못하고있는 겁니까? 도와주세요.
튜토리얼을 연습하고 DOM 및 HTML 기본 사항을 알아야합니다. – Tugrul
예외의 스택 추적을 포함하십시오. –
@DanielB : 안드로이드에서 stacktrace를 얻는 방법? 나는 그것을 토스트했지만 제대로 작동하지 못했습니다. –