i have this form with a button upon submit i retrieve stock info from yahoo finance api, and use it to display onto three textviews
the url i use
http://download.finance.yahoo.com/d/quotes.csv?s=goog&f=sl1p2
and my button event handler is
URL url;
try {
url = new URL("http://download.finance.yahoo.com/d/quotes.csv?s=goog&f=sl1p2");
InputStream stream = url.openStream();
BufferedInputStream bis = new BufferedInputStream(stream);
ByteArrayBuffer bab = new ByteArrayBuffer(50);
int current = 0;
while((current = bis.read()) != -1){
bab.append((byte) current);
}
String stockTxt = new String(bab.toByteArray());
String[] tokens = stockTxt.split(",");
String stockSymbol = tokens[0];
String stockPrice = tokens[1];
String stockChange = tokens[2];
String fstockSymbol = stockSymbol.substring(1, stockSymbol.length() -1);
String fstockChange = stockChange.substring(1, stockChange.length()-3);
symbolOut.setText(fstockSymbol);
priceOut.setText(stockPrice);
changeOut.setText(fstockChange);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
so what i noticed till the first line there seems to be no problem i.e url = new URL...,(even the bare http request done through browser, does return the info i need )
and my manifest entry looks like
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
below is the logcat output
05-02 18:36:32.804: D/AndroidRuntime(902): Shutting down VM
05-02 18:36:32.804: W/dalvikvm(902): threadid=1: thread exiting with uncaught exception (group=0x409c01f8)
05-02 18:36:33.113: E/AndroidRuntime(902): FATAL EXCEPTION: main
05-02 18:36:33.113: E/AndroidRuntime(902): android.os.NetworkOnMainThreadException
05-02 18:36:33.113: E/AndroidRuntime(902): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099)
05-02 18:36:33.113: E/AndroidRuntime(902): at java.net.InetAddress.lookupHostByName(InetAddress.java:391)
05-02 18:36:33.113: E/AndroidRuntime(902): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242)
05-02 18:36:33.113: E/AndroidRuntime(902): at java.net.InetAddress.getAllByName(InetAddress.java:220)
05-02 18:36:33.113: E/AndroidRuntime(902): at libcore.net.http.HttpConnection.<init>(HttpConnection.java:71)
so anybody knows where im going wrong