title: Reading a webpage in Eclipse android
body: <p>This is the code that is supposed to read a text from a specified website but the variable "result" simply gives me no output. I can't get the function main(null) running. it simply crashes the app whenever or wherever it is called. (am calling in onCreate() of MainActivity)</p>
  
  <pre><code>    public class ConvertUrlToString {
  
           public void main(String[] args) {
  
              try {
                  webPage = "http://www.albab.pk/albab_edu/mashal/dsms.aspx";
                  URL url = new URL(webPage);
                  URLConnection urlConnection = url.openConnection();
                  InputStream is = urlConnection.getInputStream();
                  InputStreamReader isr = new InputStreamReader(is);
  
                  int numCharsRead;
                  char[] charArray = new char[1024];
                  StringBuffer sb = new StringBuffer();
                  while ((numCharsRead = isr.read(charArray)) &gt; 0) {
                      sb.append(charArray, 0, numCharsRead);
                  }
                  result = sb.toString();
  
              } catch (MalformedURLException e) {
                  e.printStackTrace();
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
      }
  
      public void onClick(View arg0) {
          // TODO Auto-generated method stub
  
          SmsManager sms = SmsManager.getDefault();
          PendingIntent piSent = PendingIntent.getBroadcast(this, 0, new Intent("SMS_SENT"), 0);
          PendingIntent piDelivered = PendingIntent.getBroadcast(this, 0, new Intent("SMS_DELIVERED"), 0);
          sms.sendTextMessage("+923018744545", null, "Hi There!", piSent, piDelivered);
      }
  
  public void onReceive(Context arg0, Intent arg1) {
                  // TODO Auto-generated method stub
                  switch (getResultCode()) {
                  case Activity.RESULT_OK:
                      Toast.makeText(getBaseContext(), result, Toast.LENGTH_SHORT).show();
                      break;
                  case SmsManager.RESULT_ERROR_GENERIC_FAILURE:
                      Toast.makeText(getBaseContext(), "Generic Failure", Toast.LENGTH_SHORT).show();
                      break;
                  case SmsManager.RESULT_ERROR_NO_SERVICE:
                      Toast.makeText(getBaseContext(), "No Service", Toast.LENGTH_SHORT).show();
                      break;
                  case SmsManager.RESULT_ERROR_NULL_PDU:
                      Toast.makeText(getBaseContext(), "Null PDU", Toast.LENGTH_SHORT).show();
                      break;
                  case SmsManager.RESULT_ERROR_RADIO_OFF:
                      Toast.makeText(getBaseContext(), "Radio Off", Toast.LENGTH_SHORT).show();
                      break;
                  default:
                      break;
                  }
  
              }
  </code></pre>