Number format exception

gjoisa

Active Member
Licensed User
Longtime User
My app runs smoothly in almost all android devices of samsung , lg ,dell etc . but while running in iberry bt07 tab application stops and gives an error message of "number format exception" . What is the problem ?
 
Colors.White

You should check the logs for the full error message.
There are several log viewers in the market which you can use if you don't have direct access to the device.
i have this problem what is problem ?
Code: Copy
Dim cursor1 As Cursor
cursor1 = sql1.ExecQuery("SELECT * FROM mench ")
cursor1.Position = 0

Log(cursor1.getString("color"))

P1.Color = cursor1.getString("color")


but see this erorr = java.lang.NumberFormatException: Colors.White
 
Upvote 0
In this line:
Code: Copy
P1.Color = cursor1.getString("color")
You trying to set a String value to an Int value !
P1.Color is an Int.
cursor1.getString("color") is a String.
What type of variable is in the "color" column ?

Best regards.
 
Upvote 0
I see that the value received from your db is "colors.white". Note that colors.white is a number in b4a but NOT when given from another source i.e. when you supply it as a string. A solution would be to fill your colors' field with integer representations of desired colors.
 
Upvote 0
Since it appears you are storing the colors as strings as noticed by Klaus and mc73, perhaps you can do something like this:
Code: Copy
Dim strColor As String
   strColor = Cursor1.getString("color")
   P1.Color = ConvertColors(strColor)

Code: Copy
Sub ConvertColors(MyColor As String) As Int
  MyColor=MyColor.SubString(MyColor.IndexOf(".")+1).ToUpperCase
   Select MyColor
      Case "BLACK"
'        Return -16777216
        Return Colors.Black
      Case "BLUE"
        Return  Colors.Blue     '-16776961
      Case "WHITE"
        Return Colors.White
      Case "YELLOW"
        Return Colors.Yellow                  '-256
      Case "CYAN"
        Return Colors.Cyan
      Case "RED"
        Return Colors.RGB(255,0,0)    'you can use Colors.Red
      Case "MAGENTA"
        Return Colors.Magenta
   End Select
End Sub
 
Upvote 0
Back
Top