1
我想從我的android活動中的Web服務檢索一個arrayList。以下代碼不起作用:
如何解決錯誤?當我嘗試這種方式時,res是空的!如何調用返回android中的arrayList的Web服務?
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
System.out.println("qqqqqqqqqqq");
setContentView(R.layout.second);
Button submit = (Button) findViewById(R.id.b01);
submit.setOnClickListener(new View.OnClickListener()
{
public void onClick(View view)
{
Toast.makeText(getApplicationContext(), "Hello", Toast.LENGTH_SHORT).show();
EditText txt = (EditText) findViewById(R.id.editText1);
String text = txt.toString();
SoapObject request = new SoapObject(Name_Space, Method_Name);
PropertyInfo pi1 = new PropertyInfo();
pi1.setName("shopId");
pi1.setValue(text);
request.addProperty(pi1);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
try
{
System.out.println("Hellooooooooooo66666666666666");
androidHttpTransport.call(Soap_Action, envelope);
SoapPrimitive res = (SoapPrimitive) envelope.getResponse();
System.out.println("Result SP " + res);
ArrayList<Discount> result = (ArrayList<Discount>) envelope.getResponse();
Toast.makeText(getApplicationContext(), "Hi", Toast.LENGTH_SHORT).show();
System.out.println("Result in getResult() : " + res);
System.out.println("Traversing ArrayList in forward direction ");
if (res != null)
{
for (Discount ds : result)
{
discount = ds;
}
}
else
{
Toast.makeText(getApplicationContext(), "Error", Toast.LENGTH_SHORT).show();
}
Toast.makeText(getApplicationContext(), envelope.getResponse().toString(), Toast.LENGTH_SHORT)
.show();
Toast.makeText(getApplicationContext(), discount.getProductName(), Toast.LENGTH_SHORT).show();
System.out.println("Size 1111 " + result.size());
} catch (NullPointerException e)
{
e.printStackTrace();
} catch (Exception e)
{
e.printStackTrace();
}
}
}
}
感謝,
斯納
你只問問題,太給答案....偉大... – 2012-11-28 09:26:42
你好,我用你的代碼在上面的代碼由WS返回ArrayList中你已經使用折扣=新折扣((SoapObject)result.getProperty(I));在這裏你正在調用bean,你可以請你發佈你的bean,這樣我就可以理解我的代碼出了什麼問題 – varun 2013-04-22 12:26:03