안드로이드 개발 질문/답변
(글 수 40,700)
package com.example.parsing_jericho;
import java.util.*;
import com.html.net.*;
import com.html.net.Net_HTMLParse;
import android.app.*;
import android.os.*;
import android.widget.*;
public class MainActivity extends Activity {
private ArrayList<HashMap<String,String>> data;
private ListView List;
private Net_HTMLParse hp;
private SimpleAdapter Sa;
public final Handler handler = new Handler()
{
@Override
public void handleMessage(Message msg)
{
listUpdate();
}
};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
data = new ArrayList<HashMap<String,String>>();
List = (ListView)findViewById(R.id.list);
hp = new Net_HTMLParse(MainActivity.this, handler, data);
Sa = new SimpleAdapter(MainActivity.this, data, R.layout.row, new String[]{"title","author"}, new int[]{R.id.title, R.id.author});
List.setAdapter(Sa);
}
private void listUpdate()
{
Sa.notifyDataSetChanged();
}
}
▲ MainActivity.java
package com.example.parsing_jericho;
import java.io.*;
import java.net.*;
import java.util.*;
import net.htmlparser.jericho.*;
public class Parse {
public String URL;
public ArrayList<HashMap<String,String>> data;
public Source source;
public void open() throws IOException
{
URL = "주소"; // 물론 여기는 인터넷 주소를 넣었습니다.
Parser();
}
public void Parser()
{
new Thread()
{
@Override
public void run()
{
URL nURL;
try
{
nURL = new URL("URL);
data.clear();
InputStream html = nURL.openStream();
source = new Source(new InputStreamReader(html, "EUC-KR"));
List<Element> tr = source.getAllElements(HTMLElementName.TR);
String href,title = null,icon_URL,author = null;
for(int i=1; i<tr.size(); i++)
{
Element e = (Element)tr.get(i);
String tr_value = e.getAttributeValue("class");
if(tr_value != "bg")
{
Element td_tit = e.getAllElements(HTMLElementName.TD).get(2);
Element td_author = e.getAllElements(HTMLElementName.TD).get(3);
Element p = td_tit.getAllElements(HTMLElementName.P).get(0);
Element a = p.getAllElements(HTMLElementName.A).get(0);
href = a.getAttributeValue("href");
title = a.getAttributeValue("title");
Element img = td_author.getAllElements(HTMLElementName.IMG).get(0);
icon_URL = img.getAttributeValue("src");
Element span = td_author.getAllElements(HTMLElementName.SPAN).get(0);
author = span.getContent().toString();
}
HashMap<String,String> hm = new HashMap<String,String>();
hm.put("title",title);
hm.put("author",author);
data.add(hm);
}
}
catch(MalformedURLException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}.start();
}
}
▲Parse.java
에러가 대체 무슨이유로 난건지 도저히 풀리질 않아서 일단 둘다 첨부해 봅니다.
그리고 문제는 콘솔에 뜬 이 창
[2012-07-20 18:06:25 - parsing_jericho] Attempting to connect debugger to 'com.example.parsing_jericho' on port 8645
로그캣에는
E dalvikvm Could not find class 'com.html.net.Net_HTMLParse',referenced from met hold com.example.parsing_jericho.MainActivity.onCreate
W dalvikvm VFY: unable to resolve new-instance 417(Locm/html/net/Net_HTMlParse;) in Lcom/example/parsing_jericho/MainActivity;
이렇게 뜨더군요.
뭐 Net_HTMLParse가 문제인것같긴 한데 ..
문제는 콘솔창의 저 문구가 이전에도 계속 떴었다는겁니다 .
서버에서 포트를 허용을 안하는건지 아니면 뭔가 오류가 있는건지 ...
해결 부탁드리겠습니다.