Android Question How to catch this error?

Discussion in 'Android Questions' started by Alberto Michelis, Jul 25, 2015.

  1. Alberto Michelis

    Alberto Michelis Active Member Licensed 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
     

    Attached Files:

  2. Roycefer

    Roycefer Well-Known Member Licensed 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.
     
    RandomCoder likes this.
  3. Alberto Michelis

    Alberto Michelis Active Member Licensed User

    Weird... I use a sub like

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

    End Sub
    Any else I can add?
     
  4. Roycefer

    Roycefer Well-Known Member Licensed 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).
     
  5. NJDude

    NJDude Expert Licensed User

    The answer is simple, if you are returning a DOUBLE you CANNOT return an empty string.
     
    Erel and DonManfred like this.
Loading...