android.os.NetworkOnMainThreadException . Need to use async task?

Solution 1:

I guess you are trying to peform some Network operation on your main thread

NetworkOnMainThreadException from the Docs

The exception that is thrown when an application attempts to perform a networking operation on its main thread.

UPDATE:

Its Better to use AsyncTask

private class MyAsyncTask extends AsyncTask<Void, Void, Void>
    {

        ProgressDialog mProgressDialog;
        @Override
        protected void onPostExecute(Void result) {
            mProgressDialog.dismiss();
        }

        @Override
        protected void onPreExecute() {
            mProgressDialog = ProgressDialog.show(ActivityName.this, 
                                            "Loading...", "Data is Loading...");
        }

        @Override
        protected Void doInBackground(Void... params) {
           // your network operation
            return null;
        }
    }

Solution 2:

Just change target version in manifest file to lover than Honeycomb.

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="8" />

Edit: But using AsyncTask is more convenient way to solve this issue.