I try to download file from the internet with this method:
try {
URL url = new URL("http://sites.google.com/site/androidersite/text.txt");
BufferedReader in =new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) { newline character(s)
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
I also update my Android Manifest and add this lines:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
and the app crash in this line :
BufferedReader in =new BufferedReader(new InputStreamReader(url.openStream()));
and popup a log file that wrote: Source not found
Is this code running on the main application thread? What version of Android are you testing with? If it is on the main (UI) thread, that’s bad. It may be throwing a “network on main thread” exception because they discourage you from doing that 🙂
Can you provide some actual logcat output from the crash, or possibly more context for the code that is executing?