try {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet(wyvernBones); //"http://forums.zybez.net/runescape-2007-prices/3104-wyvern-bones"
HttpResponse response = httpClient.execute(httpGet, localContext);
String result = "";
BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
fetched = false;
progBox.show();
while (!fetched) {
line = br.readLine();
if (line.contains("Average Sell Offer")) {
Toast.makeText(this, line, Toast.LENGTH_LONG).show();
progBox.dismiss();
fetched = true;
}
}
} catch (Exception e) {
e.printStackTrace();
}
Above is the first approach I used.
public void getItem() throws Exception
{
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet(wyvernBones); //"http://forums.zybez.net/runescape-2007-prices/3104-wyvern-bones"
HttpResponse response = httpClient.execute(httpGet, localContext);
String result = "";
BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
fetched = false;
progBox.show();
while (!fetched) {
line = br.readLine();
if (line.contains("Average Sell Offer")) {
Toast.makeText(this, line, Toast.LENGTH_LONG).show();
progBox.dismiss();
fetched = true;
}
}
}
After using the following code inside of a try catch block with no avail, I instead put it into a method. During debugging, I realized the code inside the try/catch block wasn't even being processed/ran(?). What have I done wrong?
e: the first sample was attempted in the onCreate method, the second sample was called when a button was pressed.
Entire Code;
public class MainActivity extends ActionBarActivity implements OnClickListener{
Button btn1;
ProgressDialog progBox;
Boolean fetched;
String line;
URL url;
String wyvernBones = "http://forums.zybez.net/runescape-2007-prices/3104-wyvern-bones";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progBox = new ProgressDialog(this);
progBox.setIndeterminate(true);
progBox.setTitle("Fetching Data..");
btn1 = (Button) findViewById(R.id.btn1);
btn1.setOnClickListener(this);
try {
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet(wyvernBones); //"http://forums.zybez.net/runescape-2007-prices/3104-wyvern-bones"
HttpResponse response = httpClient.execute(httpGet, localContext);
String result = "";
BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
fetched = false;
progBox.show();
while (!fetched) {
line = br.readLine();
if (line.contains("Average Sell Offer")) {
Toast.makeText(this, line, Toast.LENGTH_LONG).show();
progBox.dismiss();
fetched = true;
}
}
} catch (Exception e) {
e.printStackTrace();
}
}