A problem with SoapObject-SoapPrimitive

  • Replies:1
Sermet Keserlioğlu
  • Forum posts: 2

Sep 24, 2016, 10:47:38 AM via Website

Hi everyone!
I have a problem. I have a web service written by me on ASP.NET with two WebMethod, both of WebMethod return type is string. In Android Studio, I can just use one of them successfully.
When I use the working method, my code is

SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
result = response.toString();

on the doInBackground() method on AsyncTask class. And then on onPostExecute() method, I can get correct result.

But when I change method like METHOD = "secondMethod"; , my code is same.

But I get an error which is :

FATAL EXCEPTION: AsyncTask #1 java.lang.RuntimeException: An error
occurred while executing doInBackground()
Caused by:
java.lang.ClassCastException: org.ksoap2.serialization.SoapObject
cannot be cast to org.ksoap2.serialization.SoapPrimitive
at
com.example.izm.obsarayuz.MSSQLConnectionAsyncTask.doInBackground(MSSQLConnectionAsyncTask.java:78)
at
com.example.izm.obsarayuz.MSSQLConnectionAsyncTask.doInBackground(MSSQLConnectionAsyncTask.java:27)
at android.os.AsyncTask$2.call(AsyncTask.java:304)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:243) 
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133) 
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607) 
at java.lang.Thread.run(Thread.java:761)

It says " SoapObject cannot be cast to org.ksoap2.serialization.SoapPrimitive " , but I'm sure returning value or type is string and I must use SoapPrimitive because of it.

Reply
Sermet Keserlioğlu
  • Forum posts: 2

Sep 24, 2016, 11:45:24 AM via Website

Oh my God ! I tried to send choosed date on datePicker as string to web service in my program, and the web service tried to send this value to MSSQL database, but on database, date column format of my records is "DD.0M.YYYY". I saw month value of datePicker is one month ago and not started "0" , for example today date is 24.09.2016, if i select 24, the value of month of datePicker is "8". What a bullshit ! Anyway, i understood this using Debugging on Android Studio. After that i did correction on it, and it's working correctly !

— modified on Sep 24, 2016, 11:47:43 AM

Reply