java - getting data from a website Api to a android app -


i have java knowledge fresh. yesterday started learning java android , encountered problem. want retrieve decimal number website api in-app calculations. have code works in normal java, when insert android studio compiles app crashes @ start. appreciated.

here's number retrieval code :

        url url = new url("api.example.com");      urlconnection con = url.openconnection();     inputstream =con.getinputstream();      bufferedreader br = new bufferedreader(new inputstreamreader(is));      string line = null;     int cont=0;      while ((line = br.readline()) != null) {         cont++;         if(cont==28){             dol = double.parsedouble(line.substring(25, 31));          }     } 

anything related networking tasks need perform in asynctask only
try in asynctask


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -