Android Question How to catch this error?

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Some times I get the image error, it allways says the problem is in my CodeModule (where I code my repetitive subs) and in NumberFormat function, but that function is not used in that module.

The times it happened to me I recompile in Debug and sometimes, not allways I found the error, sometimes not.

Problem is I try to reproduce the user error and it does not happened.

Is there eny way to trap it and to know from what line of code it is?

Thanks
 

Attachments

  • error.png
    error.png
    47.3 KB · Views: 138

Roycefer

Well-Known Member
Licensed User
Longtime User
java.lang.NumberFormatException isn't necessarily from the NumberFormat function. It's typically caused by trying to cast a String to a double. From the looks of your error message, it seems you're trying to cast an empty String to a double.

Without seeing your code, it's hard to say where it happens but this kind of error is common whenever your program prompts the user for numerical input (like in an EditText) and the user inputs an empty String and then clicks OK. To stop this from throwing that NumberFormatException, you should test user input for validity before trying to use it. Try-Catch blocks are good, as is the isNumber() function.
 
Upvote 0

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Weird... I use a sub like

B4X:
Sub TextValue(inText As String) As Double
    If IsNumber(inText.Trim.Replace(",",""))=False Then 
        Return 0
    Else   
        Return inText.trim.Replace(",","")
    End If   

End Sub

Any else I can add?
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
Try going into Objects/src/your/package/name and opening the .java file that has that function and see what's going on on line 153. You can open .java files with a normal text editor like Notepad (though you'll probably want one that displays line numbers).
 
Upvote 0
Top