Android : InputStream throws exception for the below code

on Monday, September 15, 2014


My InputStream throws exception for the below code I'm not able to find what error I have made tried from morning to debug and got feed up with it


Please help.


-------------------------------------------------------------------------------------------------



public class MainActivity extends Activity {

Element RootElement;
Element xmlElement;
Context context;
TextView textView1;
String url = "http://www.androidbegin.com", s;
ProgressDialog mProgressDialog;
String UrlLink = "http://postimg.org/gallery/5y7ulm9o/b2f8235e/";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

textView1 = (TextView) findViewById(R.id.textView1);
context = this;

Gethtml Ght = new Gethtml();
Ght.execute();
}

public class Gethtml extends AsyncTask {
ProgressDialog dialog;

@Override
protected void onPreExecute() {
// TODO Auto-generated method stub
super.onPreExecute();
dialog = new ProgressDialog(context);
dialog.setTitle("Loading");
dialog.setMessage("Html....");
dialog.show();
}

@Override
protected Object doInBackground(Object... params) {
try {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(UrlLink);
HttpResponse response = client.execute(request);
StatusLine line = response.getStatusLine();
int statuscode = line.getStatusCode();
if (statuscode != 200) {
return null;
}
/*throws error---->*/ InputStream IpStream=response.getEntity().getContent();
processXML(IpStream);
}
catch(Exception e){
Log.v("Error",e.toString());
}

return null;
}
public void processXML(InputStream IS)throws Exception{
DocumentBuilderFactory DBF=DocumentBuilderFactory.newInstance();
DocumentBuilder DB=DBF.newDocumentBuilder();
org.w3c.dom.Document xmlDocument=DB.parse(IS);
Element RootElement=xmlDocument.getDocumentElement();

}
@Override
protected void onPostExecute(Object result) {
dialog.dismiss();
Log.v("VIVZ",RootElement.getTagName());
Toast.makeText(MainActivity.this, "text", Toast.LENGTH_SHORT).show();
textView1.setText(s);
//super.onPostExecute(result);
}

}

}


Logcat


enter image description here


0 comments:

Post a Comment