Situation: I have been attempting to parse a URL and retrieve the information between the body tags and setting it in the Android Text View.
Problem: Something is wrong and/or missing..
Code:
package jsouptutorial.androidbegin.com.jsouptutorial;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.nodes.TextNode;
import org.jsoup.select.Elements;
import java.io.File;
import java.io.IOException;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView textOut = (TextView)findViewById(R.id.rootTxtView);
//------------------Something went wrong here-------------------------------
Document doc;
try {
//doc = Jsoup.connect("https://stackoverflow.com/questions/45311629/android-jsoup-parsing-url-for-all-body-text").get();
doc = Jsoup.parse(new File("https://stackoverflow.com/questions/45311629/android-jsoup-parsing-url-for-all-body-text"), "UTF-8");
Elements desc = doc.select("a.body");
textOut.setText((CharSequence) desc); //Setting textView to a String
} catch (IOException e) {
e.printStackTrace();
}
//--------------------------------------------------------------------
}
}