아두이노와 이더넷을 사용하여 만든 웹서버에 데이터를 출력하고 이를 안드로이드 어플에서도 출력하기 위해 jericho 파서를 사용하려고 합니다.
이를 하기 전에 테스트 해보고자 톰캣으로 간단한 html 페이지를 만들어 테스트를 해봤는데요. 제대로 출력이 되지 않습니다.
일단 jericho-android.3.1.jar 라이브러리를 사용했구요.
안드로이드 소스코드는 인터넷에 있는 예제를 참고하여
package com.example.testparser;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import net.htmlparser.jericho.Element;
import net.htmlparser.jericho.HTMLElementName;
import net.htmlparser.jericho.Source;
import android.app.Activity;
import android.os.Bundle;
import android.os.StrictMode;
import android.widget.TextView;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork().penaltyLog().build());
String Url = "http://localhost:8080/test/parsertest.html";
TextView textView = (TextView)findViewById(R.id.mainTextView);
textView.setText(getURLtoText(Url));
}
public String getURLtoText(String UrlString) {
Source source = null;
String content = null;
try {
source = new Source(new URL(UrlString));
source.fullSequentialParse();
Element table = source.getAllElements(HTMLElementName.TABLE).get(0);
Element tr = table.getAllElements(HTMLElementName.TR).get(0);
Element td = tr.getAllElements(HTMLElementName.TD).get(0);
content = td.getTextExtractor().toString();
content = new String(content.getBytes(source.getEncoding()),"utf-8");
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return content;
}
}
이렇게 짰구요. 매니패스트도 인터넷에서 하라는데로 수정을 했습니다.
열고자 하는 html은
<html>
<head>
<title>parser test</title>
</head>
<body>
<table>
<tr>
<td>
test
</td>
</tr>
</table>
</body>
</html>
이렇게 해놨습니다.
그런데 이를 실행시키면 어플이 죽지는 않는데,

이렇게 아무것도 뜨지 않습니다.
어떻게 해결하면 될까요?