0

我是 android 开发的新手,我正在尝试将一些值传递给 SOAP 并希望获得响应,但我收到了您尝试传递空值的异常。这是我的代码:

public class MainActivity extends Activity {

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

    new NewConfig().execute();

}
@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;
}

class NewConfig extends AsyncTask<Void, Void, Void>{
    private final String NAMESPACE = "http://tempuri.org";
    private final String URL = "http://EmoteSAPI.asmx";
    private final String SOAP_ACTION = "http://tempuri.org/SpecificSetting";
    private final String METHOD_NAME = "SpecificSetting";
    @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub


        SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
        request.addProperty("ConfigKey", "PostLength");



        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        Element[] header = new Element[1];
        header[0] = new Element().createElement("http://tempuri.org/","SecurityInfo");

        Element APIkey = new Element().createElement(null,"n0:APIKey");

        APIkey.addChild(Node.TEXT,"TestAPI");
        header[0].addChild(Node.ELEMENT,APIkey);

        Element userid = new Element().createElement(null,"n0:UserID");
        userid.addChild(Node.TEXT,"username");
        header[0].addChild(Node.ELEMENT,userid);

        Element pass = new Element().createElement(null,"n0:Password");
        pass.addChild(Node.TEXT, "password");
        header[0].addChild(Node.ELEMENT, pass);

        envelope.headerOut = header;

        envelope.setOutputSoapObject(request);
        Log.e(" ","Response Envelope"+envelope);


        try {
             HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
            androidHttpTransport.call(SOAP_ACTION, envelope);
            SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
            Log.e(" ","Response"+response.toString());

            TextView tv = (TextView) findViewById(R.id.textView1);
            tv.setText(response.toString());
            setContentView(tv);

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

        return null;
    }

}

}

这是我得到的错误:

10-08 08:31:53.464: W/System.err(6125): SoapFault - faultcode: 'soap:Client' faultstring: 'System.Web.Services.Protocols.SoapException: Error:- Null Reference Exception- You are trying to pass null.

提前致谢

4

0 回答 0