This is the code, which has to load a page and store it in string[]. I dont understand the problem as it is not loading the page and it is throwing no errors.
If any one knows any better ways to send a http request then please post it or please tell me the problem.
//some code
btnShowLocation.setOnClickListener(new View.OnClickListener() {
int j=0;
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
new MyTask().execute();});
//some code
private class MyTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
// TODO Auto-generated method stub
try {
String ssr="";
URL n = new URL("http://maps.google.co.in/maps?hl=en&q=nagpur+to+pune");
URLConnection nc = null;
nc = n.openConnection();
BufferedReader in = null;
in = new BufferedReader(new InputStreamReader(nc.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
ssr+=inputLine;
}
Document doc = Jsoup.parse(ssr);
Elements el = doc.getElementsByClass("dir-mrgnr");
String str = el.text();
str = str.replaceAll("[0-9]+[.] ", "\n");
string = str.split("\n");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void onProgressUpdate(Void... values) {
// TODO Auto-generated method stub
super.onProgressUpdate(values);
Toast.makeText(
getApplicationContext(),
"in Background",
Toast.LENGTH_LONG).show();
speakOut("not Working");
//speakOut("work in progress");
}
@Override
protected void onPostExecute(Void result) {
// TODO Auto-generated method stub
super.onPostExecute(result);
}
}
You dont need to download the page and parse it then.
Btw. dont use
+=on a String in a loop; use aStringBuilderinstdead!