Theres a "Method getText Must Be Called from the UI Thread" error under
edtUrl.getText().toString();
I Think i have to add a constructor to AsyncTask which would take the two Strings then send them when creating your task? Anyone have any ideas? Tried using another SO question just like this info but nothing worked
private class ParseURL extends AsyncTask<String, Void, String> {
private String siteUrl;
@Override
protected String doInBackground(String... strings) {
StringBuffer buffer = new StringBuffer();
//EditText edtUrl = (EditText) findViewById(R.id.edtURL);
//String siteUrl = edtUrl.getText().toString();
try {
Log.d("JSwa", "Connecting to ["+strings[0]+"]");
Document doc = Jsoup.connect(strings[0]).get();
Log.d("JSwa", "Connected to ["+strings[0]+"]");
// Get document (HTML page) title
String title = doc.title();
Log.d("JSwA", "Title ["+title+"]");
buffer.append("Title: " + title + "\r\n");
try {
doc = Jsoup.connect(siteUrl)
.userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0")
.referrer("http://www.google.com")
.timeout(1000 * 5) //it's in milliseconds, so this means 5 seconds.
.get();
} catch (Throwable t) {
t.printStackTrace();
}
Elements tableElements = doc.select("td");
for (Element td : tableElements) {
buffer.append("TT [" + td + "] \r\n");
Log.d("JSwA", "TT [" + td + "]");
}
This is my onClick(), Im getting errors under both the siteURl below.
@Override
public void onClick(View view) {
// String siteUrl = edtUrl.getText().toString();
siteUrl = "http://www.w3schools.com/html/html_tables.asp";
(new ParseURL()).execute(new String[]{siteUrl});
This is my findViewsById() method i was trying to use.
protected void onPreExecute() {
super.onPreExecute();
EditText edtUrl = (EditText) findViewById(R.id.edtURL);
siteUrl = edtUrl.getText().toString();
}
The error appear while trying to incorporate this code into my project, It is part of my parseURL method:
try {
doc = Jsoup.connect(siteUrl)
.userAgent("Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0")
.referrer("http://www.google.com")
.timeout(1000 * 5) //it's in milliseconds, so this means 5 seconds.
.get();
} catch (Throwable t) {
t.printStackTrace();
}