本文介绍了我收到错误java.lang.ClassCastException:org.ksoap2.soapfaultor输入数字是不可用的,请你找到解决方案的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 package com.example.newweb; import org.ksoap2.SoapEnvelope; import org.ksoap2.serialization.PropertyInfo; import org.ksoap2.serialization.SoapObject; import org.ksoap2.serialization.SoapSerializationEnvelope; import org.ksoap2.transport.HttpTransportSE; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.app.Activity; public class MainActivity extends 活动 { 私人 静态 final 字符串 SOAP_ACTION = http://tempuri.org/FindName; private static final 字符串 OPERATION_NAME = FindName; private static final String WSDL_TARGET_NAMESPACE = http://tempuri.org/ ; private static final String SOAP_ADDRESS = http://1675.vinna.in /android/Service.asmx; TextView tvData1; EditText edata; 按钮按钮; String studentNo; protected void onCreate(Bundle savedInstanceState) { 超 .onCreate(savedInstanceState); setContentView(R.layout.activity_main); tvData1 =(TextView)findViewById(R.id.textView1); button =(Button)findViewById(R.id.button1); button.setOnClickListener( new OnClickListener() { public void onClick(查看v) { SoapObject请求= 新 SoapObject(WSDL_TARGET_NAMESPACE ,OPERATION_NAME); PropertyInfo propertyInfo = new PropertyInfo(); propertyInfo.type = PropertyInfo.STRING_CLASS; propertyInfo.name = eid; edata =(EditText)findViewById(R.id.editText1); studentNo = edata.getText( ).toString(); request.addProperty(propertyInfo,studentNo); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS); 尝试 { httpTransport.call(SOAP_ACTION,envelope); String s = httpTransport.requestDump; SoapObject response =(SoapObject)envelope.bodyIn; tvData1.setText(response.toString()); } catch (异常异常) { tvData1.setText(exception.toString()+ 或输入数字不可用!); } tvData1 =(TextView)findViewById(R.id.textView1); } }); // client = new DefaultHttpClient(); // new Read()。execute(text); } } 解决方案 看起来你在try块的某个地方做了无效的演员。 /> 在不知道你正在使用的库的情况下我会怀疑 SoapObject response =(SoapObject)envelope.bodyIn; 我在某个地方发现了这个: SoapObject result =(SoapObject)soapEnvelope。 getResponse(); 正如我所说,我对你正在使用的库一无所知,所以我无法提供帮助。 您是否尝试在try块之前的代码中放置一个断点,然后逐步执行代码?这应该给你一些关于哪个语句真正抛出异常的信息。 另外,将返回值放在一个对象变量中然后以某种方式记录它的类型,类似于: 对象响应= envelope.bodyIn; Log.d( MainActivity,response.getClass()。toString()) ; package com.example.newweb;import org.ksoap2.SoapEnvelope;import org.ksoap2.serialization.PropertyInfo;import org.ksoap2.serialization.SoapObject;import org.ksoap2.serialization.SoapSerializationEnvelope;import org.ksoap2.transport.HttpTransportSE;import android.os.Bundle;import android.view.View;import android.view.View.OnClickListener;import android.widget.Button;import android.widget.EditText;import android.widget.TextView;import android.app.Activity;public class MainActivity extends Activity { private static final String SOAP_ACTION = "http://tempuri.org/FindName"; private static final String OPERATION_NAME = "FindName"; private static final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/"; private static final String SOAP_ADDRESS = "http://1675.vinna.in/android/Service.asmx"; TextView tvData1; EditText edata; Button button; String studentNo; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tvData1 = (TextView)findViewById(R.id.textView1); button=(Button)findViewById(R.id.button1); button.setOnClickListener(new OnClickListener() { public void onClick(View v) { SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,OPERATION_NAME); PropertyInfo propertyInfo=new PropertyInfo(); propertyInfo.type = PropertyInfo.STRING_CLASS; propertyInfo.name = "eid"; edata =(EditText)findViewById(R.id.editText1); studentNo=edata.getText().toString(); request.addProperty(propertyInfo, studentNo); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS); try { httpTransport.call(SOAP_ACTION, envelope); String s=httpTransport.requestDump; SoapObject response=(SoapObject)envelope.bodyIn; tvData1.setText(response.toString()); } catch (Exception exception) { tvData1.setText(exception.toString()+"Or enter number is not Available!"); } tvData1 = (TextView)findViewById(R.id.textView1); } }); //client = new DefaultHttpClient(); //new Read().execute("text"); }} 解决方案 Looks like you are doing an invalid cast somewhere in your try block.Without knowing anything about the library you are using i would suspectSoapObject response=(SoapObject)envelope.bodyIn;I somewhere found this:SoapObject result = (SoapObject) soapEnvelope.getResponse();As I said, I know nothing about the library you are using so I will not be able to help.Have you tried to put a breakpoint in your code just before the try block and then step through the code? This should give you some information as to which statement is really throwing the exception.Also, put the return value in an object variable and then somehow log the type of it, something like:object response=envelope.bodyIn;Log.d("MainActivity", response.getClass().toString()); 这篇关于我收到错误java.lang.ClassCastException:org.ksoap2.soapfaultor输入数字是不可用的,请你找到解决方案的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-25 00:35