PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → Strange Error Message
Strange Error Message
Débuté par Jeff Graham, 22 aoû. 2018 23:16 - 4 réponses
Posté le 22 août 2018 - 23:16
Greetings,

History: I made a simple web service for use with a client's data and android mobile phones. All was working in simulation but when I tried to run it on the phone, it would crash and send and error message. Of course, PC Solt was no help in deciphering the error message but the error occurred when assigning the result structure from the webservice. So I decided to try Serialize and Deserialize and transfer a buffer. After much more grief than expected, I got a format that should work but I get the following error:
"The element is not compatible. We expected {}stResults while we received {}stResults."

The stResults is a structure containing a string and an array of a structure.

The code is:
//aSearchResults is SearchContactsResponse arrResults is array of Answers_WS.stContactNameAddress stCurResults is Answers_WS.stResults bufRes is Buffer bufRes = Answers_WS.SearchContacts(EDT_Max_results, EDT_ID,EDT_Answers_Name,EDT_Last_Name,EDT_First_Name) Deserialize(stCurResults,bufRes,psdXML) iCount is int //stCurResults = Answers_WS.SearchContacts(EDT_Max_results, EDT_ID,EDT_Answers_Name,EDT_Last_Name,EDT_First_Name) arrResults = stCurResults.aContactNameAddress ////Deserialize(arrResults,stCurResults.aContactNameAddress,psdXML) STC_ResultsMsg..Caption = stCurResults.sMsg
The data is:
<?xml version="1.0"?>2 of 2 contacts foundCACCascade ConsultingACTIVEGrahamConniePO Box 758Port HadlockWA98339Cell Phone 350-7600CACCascade ConsultingACTIVEGrahamJeffPO Box 758Port HadlockWA98339jeff@accmeals.com350-6542

Any suggestions would be appreciated.

BTW The original error message from the android device (not using Serialize):
===== Error =====
Date and time=31/07/2018 09:38:20
Message=An error occurred while running the SOAP query.
System Message=unexpected type (position:END_DOCUMENT null@1:1 in java.io.InputStreamReader@397525c)
Process=Left-clicking WIN_Search.BTN_Search
WLanguage stack=Left-clicking WIN_Search.BTN_Search
Java stack=fr.pcsoft.wdjava.core.erreur.WDErreurManager.a(Unknown Source)
fr.pcsoft.wdjava.ws.a.d.a(Unknown Source)
fr.pcsoft.wdjava.ws.WDWSClient.invoquerMethode(Unknown Source)
com.mycompany.answers_mobile.wdgen.GWDFWIN_Search$GWDBTN_Search.clicSurBoutonGauche(GWDFWIN_Search.java:657)
fr.pcsoft.wdjava.ui.q.executerPCode(Unknown Source)
fr.pcsoft.wdjava.ui.champs.qb.executerPCode(Unknown Source)
fr.pcsoft.wdjava.ui.q.appelPCode(Unknown Source)
fr.pcsoft.wdjava.ui.champs.pb.appelPCode(Unknown Source)
fr.pcsoft.wdjava.ui.q.appelPCode_TLM(Unknown Source)
fr.pcsoft.wdjava.ui.champs.bouton.a.onClick(Unknown Source)
android.view.View.performClick(View.java:5207)
android.view.View$PerformClick.run(View.java:21168)
android.os.Handler.handleCallback(Handler.java:746)
android.os.Handler.dispatchMessage(Handler.java:95)
android.os.Looper.loop(Looper.java:148)
android.app.ActivityThread.main(ActivityThread.java:5491)
java.lang.reflect.Method.invoke(Native Method)
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
Thread=id=1
name=main
priority=5
groupName=main

===== Screen shot =====
Path=file:///storage/emulated/0/Android/data/com.mycompany.answers_mobile/cache/err1533055100700.png

===== Application =====
Application name=Answers_Mobile
Application version=0.0.8.0
Name of the package=com.mycompany.answers_mobile
Date and time of startup=31/07/2018 09:38:00
Version of Android framework=23.0.253.0 (en)

===== Device =====
Model=XT1254
Constructor=motorola
Make=motorola

===== System =====
Version number of Android=6.0.1 (M)
Android Level Api=23
Total internal storage memory=24.13 GB
Internal storage memory available=18.92 GB
Screen density=640
Screen resolution=1440x2560
Posté le 23 août 2018 - 02:52
Hi Jeff,

when it works in the simulator and not on the device, 95% of the time it's an ansi/unicode problem...

IN the simulator (which is basically a windev program), your not specified string are in ansi. on the device in unicode. and in unicode, one byte on two is a zero, which is the end of string in ansi...

That would explain the error message ...unexpected type (position:END_DOCUMENT null@1:1 in ... which seems to say that the end of document was found in position 1 of a string (ie the 0 of the unicode char is not expected)

The exact same thing is probably happening with your secod attempt and the message ...We expected {}stResults while we received {}stResults... could be interpreted as expecting unicode and receiving ansi (or the contrary)..

So your code should always use strings defined as ansi string or unicode strings, but NOT as strings and you should NEVER use a string directly (ie "myString") but always use a defined variable with your string in it. Using Edit fields directly is also a potential problem.

I explain all that and other problem in an article on my web site about the differences between simulator and real hardware run.

Best regards
Posté le 23 août 2018 - 20:03
Thanks, Fabrice.

Question for you. If your data is all in ANSI on the HF server, then is is sufficient to just declare all strings in the webservice as ANSI string or should UNICODE strings be used and the webservice convert the data to UNICODE?

BTW changing all the strings to "is ANSI string" in the buffer version of the webservice did not stop the strange error message. Does the Deserialize function detect ANSI or UNICODE in the buffer or does it assume Unicode? Looking at the buffer data in hex shows it is ANSI. Attached is simple data with all delimiters.
Posté le 23 août 2018 - 22:42
Hi Jeff,

As you data is originally ansi, you need to declare all strings as ansi on BOTH sides if you want to have a change to get something consistent.

Best regards
Posté le 25 août 2018 - 20:06
Thanks again Fabrice but I have changed both sides to use only "is ANSI strings" and the configuration is set to ANSI. Still I get the strange error message.

I will try other approaches and request tech support.