我正在处理项目并遇到问题。我想使用html清理器解析html,然后使用xpath返回一个字符串。如果它发现一个错误(它做了),我让它返回一个堆栈跟踪。我真的不知道如何根据堆栈跟踪来调试它。这是代码。HTMLcleaner堆栈跟踪错误
package ru.habrahabr.stackparser;
import java.net.URL;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.htmlcleaner.TagNode;
import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
public class stackParser extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button button = (Button) findViewById(R.id.parse);
button.setOnClickListener(myListener);
}
private ProgressDialog pd;
private OnClickListener myListener = new OnClickListener() {
public void onClick(View v) {
pd = ProgressDialog.show(stackParser.this, "Working...",
"request to server", true, false);
new parseSite()
.execute("http://wiki.teamliquid.net/starcraft2/3_Gate_Robo");
}
};
private class parseSite extends AsyncTask<String, Void, String> {
protected String doInBackground(String... arg) {
String output = new String();
try {
htmlHelper hh = new htmlHelper(new URL(arg[0]));
output = hh.htmlHelper(arg[0]);
} catch (Exception e) {
e.printStackTrace();
}
return output;
}
protected void onPostExecute(String output) {
pd.dismiss();
TextView view = (TextView) findViewById(R.id.tv1);
view.setText(output);
}
}
这里是我的HTML辅助类
package ru.habrahabr.stackparser;
import java.io.IOException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import org.htmlcleaner.CleanerProperties;
import org.htmlcleaner.HtmlCleaner;
import org.htmlcleaner.TagNode;
import org.htmlcleaner.XPatherException;
public class htmlHelper {
TagNode rootNode;
public htmlHelper(URL url) {
// TODO Auto-generated constructor stub
}
public String htmlHelper(String arg) throws IOException, XPatherException
{
CleanerProperties props = new CleanerProperties();
// set some properties to non-default values
props.setTranslateSpecialEntities(true);
props.setTransResCharsToNCR(true);
props.setOmitComments(true);
HtmlCleaner cleaner = new HtmlCleaner(props);
rootNode = cleaner.clean(arg);
Object[] nodes = rootNode.evaluateXPath("//h1[@id='firstHeading']");
String things = nodes.toString();
return things;
}
的UI和加载栏做工精细,但TextView的不断返回[Ljava.lang.Object; @ 42455a88
我会很感激一些帮助这个......我整天都在摔跤,似乎无法弄清楚。谢谢!
谢谢,但随着上述更改,我点击按钮和进度栏消失后textView只是空白。 – JP409