iOS Question Strange error

fishwolf

Well-Known Member
Licensed User
Longtime User
I have a strange error on this code in running

B4X:
Dim TimeMeteo As String
Dim NameMeteo As String

   TimeMeteo = TimeMap.Get("time")
   Log("TimeMeteo=" & TimeMeteo)
   'If TimeMeteo > Sunset Or TimeMeteo < Sunrise Then
   If TimeMeteo >= "19:00" Or TimeMeteo <= "05:00" Then
     NameMeteo = "night_"
   Else
     NameMeteo = "day_"
   End If

B4X:
TimeMeteo=19:00
An error occurred:
(Line: 413) 413
java.lang.NumberFormatException: For input string: "19:00"

but if i clean the project, this error is not present.

i have b4i 2.51 and xcode 6.5 on yosemite.
 

fishwolf

Well-Known Member
Licensed User
Longtime User
in other page i have the similar error on custom view,
if i clean the project, the app work fine

B4X:
IndTimes=1
time=04:00
TimeNext=
Error occurred on line: 44 (CustomListView)
*** -[__NSPlaceholderArray initWithObjects:count:]: attempt to insert nil object from objects[2]
Stack Trace: (
  CoreFoundation  __exceptionPreprocess + 182
  libobjc.A.dylib  objc_exception_throw + 44
  CoreFoundation  -[__NSPlaceholderArray initWithObjects:count:] + 405
  CoreFoundation  +[NSArray arrayWithObjects:count:] + 68
  MeteoSpot  -[b4i_forecasts _itemtimes::::::] + 769
  MeteoSpot  -[b4i_forecasts _showforecasts:] + 18683
  MeteoSpot  -[b4i_forecasts _jobdone:] + 4863
  CoreFoundation  __invoking___ + 29
  CoreFoundation  -[NSInvocation invoke] + 360
  MeteoSpot  +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 2069
 MeteoSpot  -[B4ICommon CallSubDebug4::::] + 894
 MeteoSpot  -[B4ICommon CallSubDebug2::::] + 350
 MeteoSpot  -[b4i_httpjob _complete::] + 887
 MeteoSpot  -[b4i_httputils2service _completejob::::] + 1723
 MeteoSpot  -[b4i_httputils2service _hc_responsesuccess::] + 771
 CoreFoundation  __invoking___ + 29
 CoreFoundation  -[NSInvocation invoke] + 360
 MeteoSpot  +[B4I runDynamicMethod:method:throwErrorIfMissing:args:] + 2069
 MeteoSpot  -[B4IShell runMethod:] + 515
 MeteoSpot  -[B4IShell raiseEventImpl:method:args::] + 2519
 MeteoSpot  -[B4IShellBI raiseEvent:event:params:] + 1623
 MeteoSpot  __61-[B4IHttp URLSession:downloadTask:didFinishDownloadingToURL:]_block_invoke + 273
 libdispatch.dylib  _dispatch_client_callout + 14
 libdispatch.dylib  _dispatch_barrier_sync_f_slow_invoke + 54
 libdispatch.dylib  _dispatch_client_callout + 14
 libdispatch.dylib  _dispatch_main_queue_callback_4CF + 677
 CoreFoundation  __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 14
 CoreFoundation  __CFRunLoopRun + 2256
 CoreFoundation  CFRunLoopRunSpecific + 443
 CoreFoundation  CFRunLoopRunInMode + 123
 GraphicsServices  GSEventRunModal + 192
 GraphicsServices  GSEventRun + 104
 UIKit  UIApplicationMain + 1526
 MyApp main + 138
 libdyld.dylib  start + 1
 ???  0x0 + 1
)
 
Upvote 0

fishwolf

Well-Known Member
Licensed User
Longtime User
Not strange at all. "19:00" is not a valid number so you cannot treat it like a number.

i would do a string compare, a number into a string is a character as "a" or "B".

B4X:
If MyString >= "AAA" Or MyString <= "BBB" Then

if is a error, why with clean project is not present?

if i remove the ":" and check

B4X:
If TimeMeteo >= "1900" Or TimeMeteo <= "0500"Then

work fine
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
You cannot compare strings like this.
B4X:
If TimeMeteo >= "1900" Or TimeMeteo <= "0500" Then
This works fine because it successfully parses the strings as numbers.

If you want to compare strings then you should use:
B4X:
TimeMeteo.CompareTo(...)

if is a error, why with clean project is not present?
It doesn't really work. It will disregard the characters after the colon. A different parser is used in that case.


Note that you should use DateTime.TimeParse instead of comparing strings.
 
Upvote 0
Top