hola estoy empezando en android y necesito que me funcione este ejemplo ya que al ejecutarlo se detiene la aplicacion. espero me puedan ayudar con peritas y manzanas, gracias
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.widget.TextView;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ActionBar SupportActionBar = getSupportActionBar();
TextView t = (TextView) findViewById(R.id.TvProba);
// deberia leer el achivo de texto
t.setText(leerFicheroUrl());
}
public static String leerFicheroUrl() {
String str1="";
String str2="";
try {
// Create a URL for the desired page
URL url = new URL("https://projecteuler.net/project/resources/p022_names.txt");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
while ((str1 = in.readLine()) != null) {
str2 = str2 + str1;
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
return str2;
}
}