URL android java flow
-
I can't open a reading flow on URL. In the manifest, I added an Internet permit.
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tv = (TextView) findViewById(R.id.txt); String s = null; s = connectToSoccer(); tv.setText(s); }
private String connectToSoccer() throws IOException { String s = null; URL url = new URL("http://www.soccer.ru"); URLConnection con = url.openConnection(); con.setConnectTimeout(1000); InputStream in = con.getInputStream(); s = StreamReader(in); return s; }
The annex is on the line
InputStream in = con.InputStream();
I've also been throughHttpURLConnection
- flight in an attempt to obtaininput stream
-
You.
NetworkOnMainThreadException
♪ C API line=14 cannot be requested in the network from the main flow of the annex. You need to get a job with a network in another flow. First, try to make it through.AsyncTask