Problem with SQL

junglejet

Active Member
Licensed User
Longtime User
The below code creates an exception when I query the length of f.actype and this string is empty.
I.e. cursor1.GetString2(13) had returned an empty SQL string in the row before.
But why is an exception thrown?
It seems to me that an empty string from SQL is different than an empty B4A string?
Thanks
Andy

B4X:
Type TFlight (actype As String)

Sub get_adata_fromsql (icao As String) As TFlight
   If sql1.IsInitialized=True Then
      Dim f As TFlight
      f.Initialize
      cursor1=sql1.ExecQuery("SELECT * from aircraft WHERE abc="& Chr(34)& icao & Chr(34))
      If cursor1.RowCount>0 Then 
         Try
            cursor1.Position=0
            f.actype=cursor1.GetString2(13) 
            If f.actype.Length=0 Then
               Log("***")
            End If
         Catch
            Log("Exception on SQL: "&icao)
         End Try
      End If
   End If
   Return f
End Sub
 

mc73

Well-Known Member
Licensed User
Longtime User
what is the real exception received if you remove the try-catch?
 
Upvote 0

junglejet

Active Member
Licensed User
Longtime User
B4X:
** Activity (main) Resume **
RESUME
main_get_adata_fromsql (java line: 2797)
java.lang.NullPointerException
   at de.jetvision.xyz.main._get_adata_fromsql(main.java:2797)
   at de.jetvision.xyz.main._http1_responsesuccess(main.java:3423)
   at java.lang.reflect.Method.invokeNative(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:511)
   at anywheresoftware.b4a.BA.raiseEvent2(BA.java:165)
   at anywheresoftware.b4a.BA$3.run(BA.java:301)
   at android.os.Handler.handleCallback(Handler.java:605)
   at android.os.Handler.dispatchMessage(Handler.java:92)
   at android.os.Looper.loop(Looper.java:137)
   at android.app.ActivityThread.main(ActivityThread.java:4512)
   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:984)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:751)
   at dalvik.system.NativeStart.main(Native Method)
java.lang.NullPointerException
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
you should run in debug mode and analyse the commented line by the debugger. then try to solve if 100% sure you get the issue.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…