ClassCastException on response

207 views
Skip to first unread message

Anagnostes

unread,
May 1, 2012, 5:46:28 AM5/1/12
to ksoap2-android
My Ksoap version is 2.6.3.

Hi, i'm trying to cast a response as an object and there is no way i
can't achieve it. I post my code:

first i've created the KvmSerializable class for testing a simple
object with one string.

public class TRespostaArticle implements KvmSerializable
{
public String Caducitat;

public TRespostaArticle(SoapObject obj){
Caducitat = "";
}

public TRespostaArticle(){
Caducitat = "";
}


public TRespostaArticle(String p_Caducitat,String p_Error,
String p_Missatge) {
Caducitat = p_Caducitat;
}

public Object getProperty(int arg0) {

switch(arg0)
{
case 0:
return "";
}
return null;
}

public int getPropertyCount() {
return 1;
}

public void getPropertyInfo(int index, Hashtable arg1,
PropertyInfo arg2) {
switch(index)
{
case 0:
arg2.type = PropertyInfo.STRING_CLASS;
arg2.name = "Caducitat";
break;
default:break;
}
}

public void setProperty(int index, Object value) {
switch(index) {
case 0:
Caducitat = value.toString();
break;
default: break;
}
}

}


Then i make the call like this.. the call is correct and i get the
response, but no way i can parse it:

SoapObject request = new SoapObject(NAMESPACE,
METHOD_NAME); //set up request
request.addProperty("p_empresa_guid", "{E5BD15A1-C3FA-413D-
A8E1-31EC60E30BD8}");
request.addProperty("p_cadena", "7013");
request.addProperty("p_Magatzem_Id", "5");
SoapSerializationEnvelope soapEnvelope = new
SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.setOutputSoapObject(request);

HttpTransportSE httpTransport = new HttpTransportSE(URL);
httpTransport.debug = true;
try {
httpTransport.call(SOAP_ACTION, soapEnvelope);
SoapObject response = (SoapObject)soapEnvelope.bodyIn; //get
response
TRespostaArticle t_s1 = (TRespostaArticle)
response.getProperty("TRespostaArticle");
String t1b = t_s1.toString();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (XmlPullParserException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

The httpTransport requestDump is :

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://
schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://
schemas.xmlsoap.org/soap/envelope/"><v:Header /
><v:Body><n0:Get_Article_Inventari_Cadena id="o0" c:root="1"
xmlns:n0="urn:InventarisIntf-IInventaris"><p_empresa_guid>{E5BD15A1-
C3FA-413D-A8E1-31EC60E30BD8}</p_empresa_guid><p_cadena>7013</
p_cadena><p_Magatzem_Id>5</p_Magatzem_Id></
n0:Get_Article_Inventari_Cadena></v:Body></v:Envelope>\r\n

And responseDump is:

<?xml version="1.0"?>\r\n<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://
schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/
XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-
ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/
encoding/"><NS1:Get_Article_Inventari_CadenaResponse
xmlns:NS1="urn:InventarisIntf-IInventaris"
xmlns:NS2="urn:utils_inventaris"><NS2:TRespostaArticle id="1"
xsi:type="NS2:TRespostaArticle"><Caducitat xsi:type="xsd:string">hola</
Caducitat></NS2:TRespostaArticle><return href="#1"/></
NS1:Get_Article_Inventari_CadenaResponse></SOAP-ENV:Body></SOAP-
ENV:Envelope>\r\n

and the response object i recive is:

Get_Article_Inventari_CadenaResponse{TRespostaArticle=TRespostaArticle{Caducitat=hola; };
return=TRespostaArticle{Caducitat=hola; }; }

I get all class of when i test it
Caused by: java.lang.ClassCastException:
org.ksoap2.serialization.SoapObject
or ..
Caused by: java.lang.ClassCastException: java.lang.String

Is there anyone who can tell me what i'm doing wrong.

Thank you very much

Manfred Moser

unread,
May 1, 2012, 11:29:47 PM5/1/12
to ksoap2-...@googlegroups.com
You got some more details where the problem happens? My observations would be that you are using bodyIn instead of getRepsonse().

Try that and report back with more details.. 

manfred

Anagnostes

unread,
May 2, 2012, 3:56:14 AM5/2/12
to ksoap2-android
Ok, i've tried getResponse with same results.

I paste the code again and debug strings, with a temporal URL for you
if you want to see the WSDL.

private static final String METHOD_NAME =
"Get_Article_Inventari_Cadena";
private static final String SOAP_ACTION = "urn:InventarisIntf-
IInventaris#Get_Article_Inventari_Cadena";
private static final String NAMESPACE = "urn:InventarisIntf-
IInventaris";
private static final String URL = "http://lab.activainfo.net/
PDAWebServicesISAPI.dll/soap/IInventaris";
.....
SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); //set up
request
request.addProperty("p_empresa_guid", "{E5BD15A1-C3FA-413D-
A8E1-31EC60E30BD8}");
request.addProperty("p_cadena", "7013");
request.addProperty("p_Magatzem_Id", "5");
SoapSerializationEnvelope soapEnvelope = new
SoapSerializationEnvelope(SoapEnvelope.VER11);
soapEnvelope.setOutputSoapObject(request);
soapEnvelope.addMapping(NAMESPACE,
TRespostaArticle.class.getSimpleName(), new
TRespostaArticle().getClass());
HttpTransportSE httpTransport = new HttpTransportSE(URL);
httpTransport.debug = true; //this is optional, use it if
you don't want to use a packet sniffer to check what the sent message
was

try {
httpTransport.call(SOAP_ACTION, soapEnvelope);
TRespostaArticle response = (TRespostaArticle)
soapEnvelope.getResponse(); //get response
.....
The exception is in this last line:

05-02 07:47:51.068: E/AndroidRuntime(404): FATAL EXCEPTION: AsyncTask
#1
05-02 07:47:51.068: E/AndroidRuntime(404): java.lang.RuntimeException:
An error occured while executing doInBackground()
05-02 07:47:51.068: E/AndroidRuntime(404): at android.os.AsyncTask
$3.done(AsyncTask.java:200)
05-02 07:47:51.068: E/AndroidRuntime(404): at
java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:
274)
05-02 07:47:51.068: E/AndroidRuntime(404): at
java.util.concurrent.FutureTask.setException(FutureTask.java:125)
05-02 07:47:51.068: E/AndroidRuntime(404): at
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
05-02 07:47:51.068: E/AndroidRuntime(404): at
java.util.concurrent.FutureTask.run(FutureTask.java:138)
05-02 07:47:51.068: E/AndroidRuntime(404): at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:
1088)
05-02 07:47:51.068: E/AndroidRuntime(404): at
java.util.concurrent.ThreadPoolExecutor
$Worker.run(ThreadPoolExecutor.java:581)
05-02 07:47:51.068: E/AndroidRuntime(404): at
java.lang.Thread.run(Thread.java:1019)
05-02 07:47:51.068: E/AndroidRuntime(404): Caused by:
java.lang.ClassCastException: org.ksoap2.serialization.SoapObject
05-02 07:47:51.068: E/AndroidRuntime(404): at
testAndroid.namespace.TestAndroidActivity
$Thread2.doInBackground(TestAndroidActivity.java:159)
05-02 07:47:51.068: E/AndroidRuntime(404): at
testAndroid.namespace.TestAndroidActivity
$Thread2.doInBackground(TestAndroidActivity.java:1)
05-02 07:47:51.068: E/AndroidRuntime(404): at android.os.AsyncTask
$2.call(AsyncTask.java:185)
05-02 07:47:51.068: E/AndroidRuntime(404): at
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
05-02 07:47:51.068: E/AndroidRuntime(404): ... 4 more

RequestDump:

<v:Envelope xmlns:i="http://www.w3.org/2001/XMLSchema-instance"
xmlns:d="http://www.w3.org/2001/XMLSchema" xmlns:c="http://
schemas.xmlsoap.org/soap/encoding/" xmlns:v="http://
schemas.xmlsoap.org/soap/envelope/"><v:Header /
><v:Body><n0:Get_Article_Inventari_Cadena id="o0" c:root="1"
xmlns:n0="urn:InventarisIntf-IInventaris"><p_empresa_guid
i:type="d:string">{E5BD15A1-C3FA-413D-A8E1-31EC60E30BD8}</
p_empresa_guid><p_cadena i:type="d:string">7013</
p_cadena><p_Magatzem_Id i:type="d:string">5</p_Magatzem_Id></
n0:Get_Article_Inventari_Cadena></v:Body></v:Envelope>\r\n

ResponseDump:

<?xml version="1.0"?>\r\n<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://
schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/
XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-
ENV:Body SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/
encoding/"
xmlns:NS2="urn:utils_inventaris"><NS1:Get_Article_Inventari_CadenaResponse
xmlns:NS1="urn:InventarisIntf-IInventaris"><return href="#1"/></
NS1:Get_Article_Inventari_CadenaResponse><NS2:TRespostaArticle id="1"
xsi:type="NS2:TRespostaArticle"><Caducitat xsi:type="xsd:string">hola</
Caducitat></NS2:TRespostaArticle></SOAP-ENV:Body></SOAP-ENV:Envelope>\r
\n

It's a Delphi 2010 dll webservice made with soap.

My intuation says it's a namespace problem, so i've tried:

soapEnvelope.addMapping("urn:utils_inventaris",
TRespostaArticle.class.getSimpleName(), new
TRespostaArticle().getClass());

But this throws another exception in the line
httpTransport.call(SOAP_ACTION, soapEnvelope);

05-02 07:53:02.008: E/AndroidRuntime(468): FATAL EXCEPTION: AsyncTask
#1
05-02 07:53:02.008: E/AndroidRuntime(468): java.lang.RuntimeException:
An error occured while executing doInBackground()
05-02 07:53:02.008: E/AndroidRuntime(468): at android.os.AsyncTask
$3.done(AsyncTask.java:200)
05-02 07:53:02.008: E/AndroidRuntime(468): at
java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java:
274)
05-02 07:53:02.008: E/AndroidRuntime(468): at
java.util.concurrent.FutureTask.setException(FutureTask.java:125)
05-02 07:53:02.008: E/AndroidRuntime(468): at
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:308)
05-02 07:53:02.008: E/AndroidRuntime(468): at
java.util.concurrent.FutureTask.run(FutureTask.java:138)
05-02 07:53:02.008: E/AndroidRuntime(468): at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:
1088)
05-02 07:53:02.008: E/AndroidRuntime(468): at
java.util.concurrent.ThreadPoolExecutor
$Worker.run(ThreadPoolExecutor.java:581)
05-02 07:53:02.008: E/AndroidRuntime(468): at
java.lang.Thread.run(Thread.java:1019)
05-02 07:53:02.008: E/AndroidRuntime(468): Caused by:
java.lang.RuntimeException: java.lang.InstantiationException:
testAndroid.namespace.TestAndroidActivity$TRespostaArticle
05-02 07:53:02.008: E/AndroidRuntime(468): at
org.ksoap2.serialization.SoapSerializationEnvelope.readInstance(SoapSerializationEnvelope.java:
433)
05-02 07:53:02.008: E/AndroidRuntime(468): at
org.ksoap2.serialization.SoapSerializationEnvelope.read(SoapSerializationEnvelope.java:
383)
05-02 07:53:02.008: E/AndroidRuntime(468): at
org.ksoap2.serialization.SoapSerializationEnvelope.parseBody(SoapSerializationEnvelope.java:
145)
05-02 07:53:02.008: E/AndroidRuntime(468): at
org.ksoap2.SoapEnvelope.parse(SoapEnvelope.java:140)
05-02 07:53:02.008: E/AndroidRuntime(468): at
org.ksoap2.transport.Transport.parseResponse(Transport.java:100)
05-02 07:53:02.008: E/AndroidRuntime(468): at
org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:197)
05-02 07:53:02.008: E/AndroidRuntime(468): at
org.ksoap2.transport.HttpTransportSE.call(HttpTransportSE.java:95)
05-02 07:53:02.008: E/AndroidRuntime(468): at
testAndroid.namespace.TestAndroidActivity
$Thread2.doInBackground(TestAndroidActivity.java:158)
05-02 07:53:02.008: E/AndroidRuntime(468): at
testAndroid.namespace.TestAndroidActivity
$Thread2.doInBackground(TestAndroidActivity.java:1)
05-02 07:53:02.008: E/AndroidRuntime(468): at android.os.AsyncTask
$2.call(AsyncTask.java:185)
05-02 07:53:02.008: E/AndroidRuntime(468): at
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:306)
05-02 07:53:02.008: E/AndroidRuntime(468): ... 4 more

I don't know what's happening, but as i can't debug your jar i can't
help more sorry.

THank you very much.
> > encoding/ <http://schemas.xmlsoap.org/soap/encoding/>"><NS1:Get_Article_Inventari_CadenaResponse

Manfred Moser

unread,
May 2, 2012, 1:28:02 PM5/2/12
to ksoap2-...@googlegroups.com
02 07:53:02.008: E/AndroidRuntime(468): Caused by:
java.lang.RuntimeException: java.lang.InstantiationException:
testAndroid.namespace.TestAndroidActivity$TRespostaArticle
05-02 07:53:02.008: E/AndroidRuntime(468): at
org.ksoap2.serialization.SoapSerializationEnvelope.readInstance(SoapSerializationEnvelope.java:
433)
05-02 07:53:02.008: E/AndroidRuntime(468): at

Debug right where it says the problem occurs and take it from there ..
also confirm that the response is what you expected it to be. Seems
like something is wrong when it tries to instantiate your
TRespostaArticle object..

manfred

Jaume Llunell Gómez

unread,
May 2, 2012, 1:30:10 PM5/2/12
to ksoap2-...@googlegroups.com
What

2012/5/2 Manfred Moser <mos...@gmail.com>

Manfred Moser

unread,
May 2, 2012, 1:33:22 PM5/2/12
to ksoap2-...@googlegroups.com
Sorry... I misread the stack trace.. must be something else it is
trying to instantiate. You will have to debug this into the framework
code to see what is going on.

Just hook the library source code into your project and debug it.

manfred

Anagnostes

unread,
May 2, 2012, 1:35:23 PM5/2/12
to ksoap2-android
Sorry, i send my last email wrong.

What do you mean debug from there?

I've debugged many times with many variations and allways throws that
two class exceptions . But i can't debug your code because i think
there is no source code only jars.So i can't see what's happening
behind the scene.

Caused by:
java.lang.ClassCastException: org.ksoap2.serialization.SoapObject

Caused by:
java.lang.RuntimeException: java.lang.InstantiationException:
testAndroid.namespace.TestAndroidActivity$TRespostaArticle

How can i attach the source code to the jar? I have ksoap2-android-
assembly-2.6.3-jar-with-dependencies.jar but it ask for source code...
where is it?





On 2 mayo, 19:30, Jaume Llunell Gómez <jaumellun...@gmail.com> wrote:
> What
>
> 2012/5/2 Manfred Moser <mosa...@gmail.com>
>
>
>
>
>
>
>
> > 02 07:53:02.008: E/AndroidRuntime(468): Caused by:
> > java.lang.RuntimeException: java.lang.InstantiationException:
> > testAndroid.namespace.TestAndroidActivity$TRespostaArticle
> > 05-02 07:53:02.008: E/AndroidRuntime(468):      at
>
> > org.ksoap2.serialization.SoapSerializationEnvelope.readInstance(SoapSerializationEnvelope.java:
> > 433)
> > 05-02 07:53:02.008: E/AndroidRuntime(468):      at
>
> > Debug right where it says the problem occurs and take it from there ..
> > also confirm that the response is what you expected it to be. Seems
> > like something is wrong when it tries to instantiate your
> > TRespostaArticle object..
>
> > manfred
>
> > On Wed, May 2, 2012 at 12:56 AM, Anagnostes <jaumellun...@gmail.com>
> ...
>
> leer más »

Manfred Moser

unread,
May 2, 2012, 1:40:41 PM5/2/12
to ksoap2-...@googlegroups.com
On Wed, May 2, 2012 at 10:35 AM, Anagnostes <jaumel...@gmail.com> wrote:
> Sorry, i send my last email wrong.
>
> What do you mean debug from there?
>
> I've debugged many times with many variations and allways throws that
> two class exceptions . But i can't debug your code because i think
> there is no source code only jars.So i can't see what's happening
> behind the scene.
>
> Caused by:
> java.lang.ClassCastException: org.ksoap2.serialization.SoapObject
>

What object is it when this cast fails?

> Caused by:
> java.lang.RuntimeException: java.lang.InstantiationException:
> testAndroid.namespace.TestAndroidActivity$TRespostaArticle

Same here... what is it trying to instantiate? Where?


> How can i attach the source code to the jar? I have ksoap2-android-
> assembly-2.6.3-jar-with-dependencies.jar but it ask for source code...
> where is it?

That depends on the IDE and your tool chain. If you build your app
with Android Maven Plugin it does it all automatically with m2eclipse
or intellij. Otherwise you have to manually hook it in. The source is
on github in source format or on google code as sources jars for the
different sub libraries.. yes.. with ant this is painful ..

manfred

Jaume Llunell Gómez

unread,
May 2, 2012, 1:49:09 PM5/2/12
to ksoap2-...@googlegroups.com
Thank you very much, i'll try to fix my error.

2012/5/2 Manfred Moser <mos...@gmail.com>
Reply all
Reply to author
Forward
0 new messages