i'm trying to returns an array of objects with KSOAP i get error in this line:
result = (SoapObject) envelope.getResponse();
there is my code:
public static List<Smartphone> GetAllSmart() {
SoapObject result=null;
try {
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new
StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = false;
envelope.setOutputSoapObject(request);
//envelope.encodingStyle = SoapSerializationEnvelope.XSD;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
androidHttpTransport.call(SOAP_ACTION, envelope);
result = (SoapObject) envelope.getResponse();
} catch (IOException e) {
Log.d("Error", "Some exception occurred", e);
} catch (XmlPullParserException e) {
Log.d("Error", "Some exception occurred", e);
} catch (NetworkOnMainThreadException e) {
Log.d("Error", "Some exception occurred", e);
}
return RetrieveFromSoap(result);
}
public static List<Smartphone> RetrieveFromSoap(SoapObject soap) {
ArrayList<Smartphone> ss = new ArrayList<Smartphone>();
for (int i = 0; i < soap.getPropertyCount(); i++) {
Smartphone smart = new Smartphone();
int j=0;
for(j=0; j<6;j++){
smart.setProperty(j, soap.getProperty(i));
}
ss.add(smart);
}
return ss;
}
thanks for ur help..
My solution:
Vector<SoapObject> result = null;
ArrayList<Smartphone> ss = new ArrayList<Smartphone>();
Smartphone smart;
try {
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new
StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
}
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = false;
envelope.setOutputSoapObject(request);
//envelope.encodingStyle = SoapSerializationEnvelope.XSD;
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
envelope.addMapping(NAMESPACE, "Smartphone", new Smartphone().getClass());
androidHttpTransport.call(SOAP_ACTION, envelope);
result = (Vector<SoapObject>) envelope.getResponse();
int length = result.size();
for (int i = 0; i < length; ++i) {
SoapObject so = result.get(i);
smart = new Smartphone();
for (int j = 0; j < so.getPropertyCount(); j++) {
smart.setProperty(j, so.getProperty(j));
}
ss.add(smart);
}
} catch (IOException e) {
Log.d("Error", "Some exception occurred", e);
} catch (XmlPullParserException e) {
Log.d("Error", "Some exception occurred", e);
} catch (NetworkOnMainThreadException e) {
Log.d("Error", "Some exception occurred", e);
}