Hi...
This is part of the code for the application and calculate route ... I get an error on this line
ResponseRoute = JSON.NextObject
Error:
java.lang.RuntimeException: JSON Object expected.
at anywheresoftware.b4a.objects.collections.JSONParser.NextObject(JSONParser.java:47)
at uk.co.martinpearman.b4a.osmdroiddemo.main._jobdone(main.java:545)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:173)
at anywheresoftware.b4a.keywords.Common$5.run(Common.java:957)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5306)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
This is part of the code for the application and calculate route ... I get an error on this line
ResponseRoute = JSON.NextObject
Error:
java.lang.RuntimeException: JSON Object expected.
at anywheresoftware.b4a.objects.collections.JSONParser.NextObject(JSONParser.java:47)
at uk.co.martinpearman.b4a.osmdroiddemo.main._jobdone(main.java:545)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:173)
at anywheresoftware.b4a.keywords.Common$5.run(Common.java:957)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5306)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)
at dalvik.system.NativeStart.main(Native Method)
B4X:
Sub Button1_Click
Dim STARTING_POINT_LAT,STARTING_POINT_LON,END_POINT_LAT,END_POINT_LON As Double
Dim job1, job2, job3 As HttpJob
Dim Richiesta As String
STARTING_POINT_LAT=46.00000
STARTING_POINT_LON=11.00000
END_POINT_LAT=45.00000
END_POINT_LON=9.00000
Richiesta="http://maps.googleapis.com/maps/api/directions/xml?origin=" & STARTING_POINT_LAT &"," & STARTING_POINT_LON & "&destination=" & END_POINT_LAT & "," & END_POINT_LON & "&sensor=false"
job1.Initialize("Job1", Me)
job1.Download(Richiesta)
ProgressDialogShow("Calculation route...")
End Sub
B4X:
Sub JobDone (Job As HttpJob)
If Job.Success = True Then
Log(Job.GetString)
Dim tw As TextWriter
If File.Exists(File.DirDefaultExternal, "Route.json") Then
File.Delete(File.DirDefaultExternal, "Route.json")
End If
tw.Initialize(File.OpenOutput( File.DirDefaultExternal,"Route.json", False))
tw.Write(Job.GetString)
tw.Close
ToastMessageShow("Succes create Route, position file" & File.DirDefaultExternal & "Name: Route.json",True)
Dim ResponseString As String
Dim ResponseRoute As Map
ResponseRoute.Initialize
ResponseString=File.ReadString(File.DirDefaultExternal, "Route.json")
Dim JSON As JSONParser
JSON.Initialize(ResponseString)
ResponseRoute = JSON.NextObject
If ResponseRoute.Get("status")="OK" Then
code for parsing....