gpt4 book ai didi

android - KSOAP: "org.ksoap2.serialization.SoapPrimitive"异常问题

转载 作者:行者123 更新时间:2023-11-30 04:36:08 27 4
gpt4 key购买 nike

我在调用网络服务时遇到问题,我在服务器中有一个 .NET 网络服务,我在 Android 中使用 KSOAP(ksoap2-android-assembly-2.5.7-jar-with-dependencies.jar)。在运行该程序时,我得到了一个名为“org.ksoap2.serialization.SoapPrimitive”的运行时异常。

我尝试使用我在链接中阅读的选项:How to call a .NET Webservice from Android using KSOAP2?kSoap2 Android -- Cast Class Exception (SoapObject)但对我没有任何帮助

这是我的代码:

try{
//Conexión a Web Service
SoapObject Solicitud = new SoapObject(NAMESPACE, METODO);

PropertyInfo sector = new PropertyInfo();
sector.setName("sector");
sector.setValue(sectorX.toString());
Solicitud.addProperty(sector);

SoapSerializationEnvelope Envoltorio = new SoapSerializationEnvelope (SoapEnvelope.VER12);
Envoltorio.dotNet = true;

Envoltorio.setOutputSoapObject (Solicitud);

HttpTransportSE TransporteHttp = new HttpTransportSE(URL);
TransporteHttp.call (SOAP_ACTION, Envoltorio);

//Obtencion de datos
SoapObject resultado = (SoapObject)Envoltorio.getResponse();

final String[] testValues = new String[resultado.getPropertyCount()];
final Number[] serie = new Number[resultado.getPropertyCount()];

for(int i= 0; i< resultado.getPropertyCount(); i++){
String x = "";
SoapObject wii = (SoapObject)resultado.getProperty(i);
x += wii.getPropertyAsString(1);
testValues[i] = wii.getPropertyAsString(1);
x.trim();
serie[i]=Integer.parseInt(x);
}

ArrayAdapter<String> adaptador = new ArrayAdapter<String>(this, R.layout.lista_sectores, testValues);
final ListView LstOpciones = (ListView) findViewById(R.id.LstOpciones);
LstOpciones.setAdapter(adaptador);

LstOpciones.setOnItemClickListener(new AdapterView.OnItemClickListener() {

@Override
public void onItemClick(AdapterView<?> parent, View itemClicked,
int position, long id) {
// TODO Auto-generated method stub
TextView textview = (TextView)itemClicked;
String strText = textview.getText().toString();
seleccion.setText("Seleccionado: " + strText);

} catch (Exception e){
txtMensaje.setText(e.getMessage());
}

其中 sectorX 是我给 WS 的字符串参数。

我尝试了不带参数的 Web 服务并且成功了!问题是当我发送参数时...我猜:/

最佳答案

那个名字也不异常(exception)。您可能会遇到类转换异常。如果您进行调试,您可能会发现您的响应是一个 SoapObject。那么你就可以使用 getProperty 或 getAttribute 或其他任何东西。如果您设置断点,您将能够浏览对象图并手动组装您的解析代码..

也许在某处发布堆栈跟踪..

关于android - KSOAP: "org.ksoap2.serialization.SoapPrimitive"异常问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6818602/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com