Use of AsyncTask in my application solved it. Or else you can use the following code in your mainactivity below setcontentview
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
This is not a recommended way of solving this kind of errors in android, but at times when you are needy, you can use it. But I would not recommend doing this.