私はアンドロイド開発に不慣れで、SOAPに値を渡そうとしていて、応答を得たいと思っていますが、null値を渡そうとしていることを例外にしています。これが私のコードです:
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.
前もって感謝します