Q:

NetworkOnMainThreadException on doing a soap request

I'm trying to do a soap request according to this WSDL scheme:
http://pastebin.com/UT3t5XdQ
This is my app code:
private final String SOAP_ACTION = "https://t4t.services.telenet.be/TelemeterService";
    private final String NAMESPACE = "http://www.telenet.be/TelemeterService/";
    private final String METHOD_NAME = "RetrieveUsageRequestType";
    private final String URL = "https://t4t.services.telenet.be/TelemeterService.wsdl";

    private Button sendButton;
    private TextView responseView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        sendButton = (Button) findViewById(R.id.send);
        responseView = (TextView) findViewById(R.id.response);

        sendButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

                //Parameters
                request.addProperty("UserId","test@telenet.be");
                request.addProperty("Password","test");

                //Version Soap
                SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

                envelope.setOutputSoapObject(request);
                envelope.dotNet = true;

                try {
                    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

                    //Call the webservice
                    androidHttpTransport.call(SOAP_ACTION, envelope);

                    // Get the result
                    SoapObject result = (SoapObject)envelope.bodyIn;

                    if(result != null)
                    {
                        Log.d("Debug","Result");
                        responseView.setText(result.getProperty(0).toString());
                    }
                    else
                    {
                        Toast.makeText(getApplicationContext(), "No Response", Toast.LENGTH_LONG).show();
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });

In my manifest I added the permission for the internet.
I'm getting this exception:
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ android.os.NetworkOnMainThreadException
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1145)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at java.net.InetAddress.lookupHostByName(InetAddress.java:385)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at java.net.InetAddress.getAllByNameImpl(InetAddress.java:236)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at java.net.InetAddress.getAllByName(InetAddress.java:214)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at com.android.okhttp.internal.Dns$1.getAllByName(Dns.java:28)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at com.android.okhttp.internal.http.RouteSelector.resetNextInetSocketAddress(RouteSelector.java:216)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at com.android.okhttp.internal.http.RouteSelector.next(RouteSelector.java:122)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:292)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at com.android.okhttp.internal.http.HttpEngine.sendSocketRequest(HttpEngine.java:255)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at com.android.okhttp.internal.http.HttpEngine.sendRequest(HttpEngine.java:206)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:345)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl.java:89)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at com.android.okhttp.internal.http.HttpURLConnectionImpl.getOutputStream(HttpURLConnectionImpl.java:197)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at com.android.okhttp.internal.http.HttpsURLConnectionImpl.getOutputStream(HttpsURLConnectionImpl.java:254)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at org.ksoap2.transport.ServiceConnectionSE.openOutputStream(ServiceConnectionSE.java:126)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:185)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:118)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:113)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at test.example.com.MainActivity$1.onClick(MainActivity.java:54)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at android.view.View.performClick(View.java:4438)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at android.view.View$PerformClick.run(View.java:18422)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at android.os.Handler.handleCallback(Handler.java:733)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:95)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at android.os.Looper.loop(Looper.java:136)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5017)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at java.lang.reflect.Method.invokeNative(Native Method)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:515)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-23 09:05:57.933    1454-1454/test.example.com W/System.err﹕ at dalvik.system.NativeStart.main(Native Method)

A:

I solved the problem like Spring breaker suggested.
private Button sendButton;
private TextView responseView;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    sendButton = (Button) findViewById(R.id.send);
    responseView = (TextView) findViewById(R.id.response);

    sendButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            new SetTreasureBoxAsyncTask().execute();
        }

    });
}
private class SetTreasureBoxAsyncTask extends AsyncTask<String, String, String>
{
    SoapObject result = null;

    @Override
    protected void onPreExecute() {
        super.onPreExecute();
    }
    @Override
    protected String doInBackground(String... params) {

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

        //Parameters
        request.addProperty("UserId","test@telenet.be");
        request.addProperty("Password","test");

        //Version Soap
        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        envelope.setOutputSoapObject(request);
        envelope.dotNet = true;

        try {
            HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

            //Call the webservice
            androidHttpTransport.call(SOAP_ACTION, envelope);

            // Get the result
            result = (SoapObject)envelope.bodyIn;

        } catch (Exception e) {
            e.printStackTrace();
        }

        if(result != null)
            return result.toString();
        else
            return null;
    }

    @Override
    protected void onPostExecute(String res) {
        super.onPostExecute(res);
        if(result != null)
        {
            Log.d("Debug", "Result");
            responseView.setText(result.getProperty(0).toString());
        }
        else
        {
            Toast.makeText(getApplicationContext(), "No Response", Toast.LENGTH_LONG).show();
        }
    }

}

The problem was the task took to long. 

