本文介绍了org.ksoap2.serialization.SoapObject不能转换为org.ksoap2.serialization.SoapPrimitive的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想显示从SOAP的Web服务,但每次都得到最新一个ListView我得到一个异常:
org.ksoap2.serialization.SoapObject不能转换为org.ksoap2.serialization.SoapPrimitive
code: -
公共类ClientsReclamations延伸活动{
公共最后弦乐NAMESPACE =http://tempuri.org/;
公共最后弦乐SOAP_ACTION =http://tempuri.org/GetReclamations;
公共最后弦乐METHOD_NAME =GetReclamations; LV的ListView; @覆盖
保护无效的onCreate(捆绑savedInstanceState){
super.onCreate(savedInstanceState); 的setContentView(R.layout.clients_reclamations);
LV =(ListView控件)findViewById(R.id.listViewRec); AsyncCallWS任务=新AsyncCallWS();
task.execute();
} 公共类AsyncCallWS扩展的AsyncTask<字符串,字符串,ArrayList的> {
ArrayList的<整治与GT; resultats =新的ArrayList<整治与GT;();
保护无效onPostExecute(ArrayList的<整治与GT; resultats){
lv.setAdapter(新CustomListAdapterRec(getApplicationContext(),resultats));
super.onPostExecute(resultats);
}
保护的ArrayList doInBackground(字符串... PARAMS){ SoapObject要求=新SoapObject空间(namespace,METHOD_NAME);
SoapSerializationEnvelope信封=新SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = TRUE;
envelope.setOutputSoapObject(请求);
HttpTransportSE androidHttpTransport =新HttpTransportSE(的getURL());
尝试{
androidHttpTransport.call(SOAP_ACTION,信封);
最终SoapObject响应=(SoapObject)envelope.getResponse();
Log.i(清单当然建议:----,response.toString());
runOnUiThread(新的Runnable(){
@覆盖
公共无效的run(){
填海区填海工程;
SoapObject GetReclamationsResponse =新SoapObject();
SoapObject GetReclamationsResult =新SoapObject();
SoapObject填海工程=新SoapObject();
SoapObject REC =新SoapObject(); GetReclamationsResponse =(SoapObject)response.getProperty(0);
GetReclamationsResult =(SoapObject)GetReclamationsResponse.getProperty(0);
填海=(SoapObject)GetReclamationsResult.getProperty(0);
的for(int i = 0; I< Reclamations.getPropertyCount();我++){ REC =(SoapObject)Reclamations.getProperty(填海工程); SoapObject DateRec =新SoapObject();
SoapObject Objet公司=新SoapObject();
SoapObject详细=新SoapObject();
SoapObject Traitee =新SoapObject(); DateRec =(SoapObject)REC.getProperty(DateRec);
Objet公司=(SoapObject)REC.getProperty(Objet公司);
详情=(SoapObject)REC.getProperty(详细信息);
Traitee =(SoapObject)REC.getProperty(Traitee); 填海=新填海工程();
reclamation.setDET_REC(Details.toString());
reclamation.setOBJET_REC(Objet.toString());
reclamation.setDate(DateRec.toString());
reclamation.setIcon(getResources()getDrawable(R.id.btn_yearly));
resultats.add(回收);
Log.i(Resultat尺寸:------,resultats.size()+);
}
}
});
}
赶上(例外五){
e.printStackTrace(); } 返回resultats; } } 公共无效AfficheToast(){
吐司T = Toast.makeText(这一点,Aucune填海trouvée。Toast.LENGTH_LONG);
t.setGravity(Gravity.CENTER,0,0);
t.show();
}
公共字符串的getURL()
{
字符串URL = NULL;
共享preferences SP = preferenceManager.getDefaultShared preferences(本);
URL = sp.getString(serveur,);
返回URL;
}
}
解决方案
更改此:
最后SoapObject响应=(SoapObject)envelope.getResponse();
到
SoapPrimitive响应=(SoapPrimitive)envelope.getResponse();
I'm trying to display a Listview by getting date from SOAP Web Service but every time i get an exception :
org.ksoap2.serialization.SoapObject cannot be cast to org.ksoap2.serialization.SoapPrimitive
code :-
public class ClientsReclamations extends Activity {
public final String NAMESPACE = "http://tempuri.org/";
public final String SOAP_ACTION = "http://tempuri.org/GetReclamations";
public final String METHOD_NAME = "GetReclamations";
ListView lv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.clients_reclamations);
lv=(ListView)findViewById(R.id.listViewRec);
AsyncCallWS task = new AsyncCallWS();
task.execute();
}
public class AsyncCallWS extends AsyncTask<String, String,ArrayList>{
ArrayList<Reclamation> resultats=new ArrayList<Reclamation>();
protected void onPostExecute(ArrayList<Reclamation> resultats) {
lv.setAdapter(new CustomListAdapterRec(getApplicationContext(), resultats));
super.onPostExecute(resultats);
}
protected ArrayList doInBackground(String... params) {
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
envelope.setOutputSoapObject(request);
HttpTransportSE androidHttpTransport = new HttpTransportSE(getURL());
try{
androidHttpTransport.call(SOAP_ACTION, envelope);
final SoapObject response = (SoapObject)envelope.getResponse();
Log.i("Liste Rec:----", response.toString());
runOnUiThread(new Runnable() {
@Override
public void run() {
Reclamation reclamation;
SoapObject GetReclamationsResponse=new SoapObject();
SoapObject GetReclamationsResult=new SoapObject();
SoapObject Reclamations=new SoapObject();
SoapObject REC=new SoapObject();
GetReclamationsResponse=(SoapObject) response.getProperty(0);
GetReclamationsResult=(SoapObject) GetReclamationsResponse.getProperty(0);
Reclamations=(SoapObject) GetReclamationsResult.getProperty(0);
for(int i=0;i<Reclamations.getPropertyCount();i++){
REC=(SoapObject) Reclamations.getProperty("Reclamation");
SoapObject DateRec=new SoapObject();
SoapObject Objet=new SoapObject();
SoapObject Details=new SoapObject();
SoapObject Traitee=new SoapObject();
DateRec=(SoapObject) REC.getProperty("DateRec");
Objet=(SoapObject) REC.getProperty("Objet");
Details=(SoapObject) REC.getProperty("Details");
Traitee=(SoapObject) REC.getProperty("Traitee");
reclamation = new Reclamation();
reclamation.setDET_REC(Details.toString());
reclamation.setOBJET_REC(Objet.toString());
reclamation.setDate(DateRec.toString());
reclamation.setIcon(getResources().getDrawable(R.id.btn_yearly));
resultats.add(reclamation);
Log.i("Resultat Size : ------",resultats.size()+"");
}
}
});
}
catch(Exception e){
e.printStackTrace();
}
return resultats;
}
}
public void AfficheToast(){
Toast t=Toast.makeText(this, "Aucune reclamation trouvée.", Toast.LENGTH_LONG);
t.setGravity(Gravity.CENTER, 0, 0);
t.show();
}
public String getURL()
{
String URL=null;
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
URL=sp.getString("serveur", "");
return URL;
}
}
解决方案
Change this: final SoapObject response = (SoapObject)envelope.getResponse();
to
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
这篇关于org.ksoap2.serialization.SoapObject不能转换为org.ksoap2.serialization.SoapPrimitive的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!