为什么这是Android应用程序中的ksoap2中断

时间:2014-01-23 14:30:54

标签: java android

在我的Android应用程序中,你能告诉我为什么会中断,我已经将ksoap2-android-assembly-3.1.1-jar-with-dependencies.jar添加到lib文件夹中。然后尝试休息。

这是错误

enter image description here

package com.example.test;

import org.ksoap2.*;
import org.ksoap2.serialization.*;
import org.ksoap2.transport.*;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;



public class MainActivity extends Activity {





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


        String Sf = celsiusToFahrenheit("2");

    }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }


    private static final String METHOD_NAME = "CelsiusToFahrenheit";
    private static final String NAMESPACE = "http://tempuri.org/";
    private static final String SOAP_ACTION = "http://tempuri.org/CelsiusToFahrenheit";
    private static final String URL = "http://www.w3schools.com/webservices/tempconvert.asmx";

    public String celsiusToFahrenheit(String celsius) {
        String fahrenheit = null;

        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
        request.addProperty("Celsius", celsius);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);

        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        androidHttpTransport.debug = true;

        try {
            androidHttpTransport.call(SOAP_ACTION, envelope);
            SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
            fahrenheit = response.toString();
        } catch (Exception e) {
            e.printStackTrace();
            fahrenheit = null;
        }
        return fahrenheit;
    }


}

0 个答案:

没有答案