B4J Question [SOLVED???] java.lang.NumberFormatException: empty String

rosippc64a

Active Member
Licensed User
Longtime User
Hi All,
I encountered a weird error and can't solve it, where is the number? I just want to ask whether in the map there is a key, isn't it?
I renamed the variable name dbinimap, the key ("beepath"), may this is the reason of error, but not. If I delete the line if ... containskey, and read the value: dbinimap.get("bexepath"), then the error goes to that line. The program exit, without could go into the catch!

B4X:
    Dim backupexepath As String = "" '"c:\Program Files (x86)\PostgreSQL\9.0\bin\pg_dump.exe"
    If File.Exists(File.DirApp,Codebase.PGSETINI)=True Then
        'hálózatban minden munkaállomáson be kell állítani egyszer a db ip címét!
        dbinimap = File.ReadMap(File.DirApp,Codebase.PGSETINI)
        Try
            If dbinimap.IsInitialized=True Then
                If dbinimap.ContainsKey("bexepath")=True Then '<----- java.lang.NumberFormatException: empty String
                    backupexepath = "" & dbinimap.Get("bexepath")
                End If
            End If
        Catch
            backupexepath = ""
        End Try
    End If
The file what readmap will read:
B4X:
#Thu Jul 23 14:20:35 CEST 2020
dblocation=127.0.0.1

The error:
B4X:
An error occurred:
(Line: 448) 448
java.lang.NumberFormatException: empty String
 

Jorge M A

Well-Known Member
Licensed User
Longtime User
B4X:
B4X:
#Thu Jul 23 14:20:35 CEST 2020
dblocation=127.0.0.1
This does not correspond to the structure of a map.

Map is a collection that maps keys to values.
It can also be named hashtable, dictionary or associative array.


Each item is made of a key and value. Access to the value is always done through the key.

Ref:

File. ReadMap (Dir As String, FileName As String) As Map
Reads the file and parses each line as a key-value pair (of strings).
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
This does not correspond to the structure of a map.

Map is a collection that maps keys to values.
It can also be named hashtable, dictionary or associative array.


Each item is made of a key and value. Access to the value is always done through the key.

Ref:

File. ReadMap (Dir As String, FileName As String) As Map
Reads the file and parses each line as a key-value pair (of strings).
But yes, that file was written by file.writemap(...)
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Are you producing the error message in Debug mode or Release mode? It makes a difference as to what the line numbers refer to (My off the cuff guess: Release mode, just a guess though)
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
In debug mode the error message is only 3 lines, in release mode this:
B4X:
Adatbázis mentése
main$ResumableSub_dbBackup.resume (java line: 655)
java.lang.NumberFormatException: empty String
    at java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1842)
    at java.base/jdk.internal.math.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
    at java.base/java.lang.Double.parseDouble(Double.java:543)
    at b4j.leiszamla.main$ResumableSub_dbBackup.resume(main.java:655)
    at b4j.leiszamla.main._dbbackup(main.java:520)
    at b4j.leiszamla.main$ResumableSub_MenuBar1_Action.resume(main.java:1156)
    at b4j.leiszamla.main._menubar1_action(main.java:968)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:91)
    at anywheresoftware.b4a.BA$1.run(BA.java:216)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    at java.base/java.lang.Thread.run(Thread.java:834)
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
the error happen in this line (the java source of the bas file):
B4X:
//BA.debugLineNum = 449;BA.debugLine="bep = dbinimap.GetDefault(\"backupexepath\",\"\")";
_bep = BA.ObjectToString(_dbinimap.GetDefault((Object)("backupexepath"),(Object)("")));
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
If I put value into the ini (map) file, even though it will exited with
B4X:
An error occurred:
(Line: 449) 449
java.lang.NumberFormatException: empty String
error message.
Map file:
B4X:
#Thu Jul 23 14:20:35 CEST 2020
backupexepath=c:\\Program Files (x86)\\PostgreSQL\\9.0\\bin\\pg_dump.exe
dblocation=127.0.0.1
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
i have no problem reading the map
 

Attachments

  • capture.png
    capture.png
    10.4 KB · Views: 305
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
I was stupid (again), but in the debug mode the program exited there. The mistake (lower!):
B4X:
    Dim dbinimap As Map
    Dim bep As String = "" '"c:\Program Files (x86)\PostgreSQL\9.0\bin\pg_dump.exe"
    If File.Exists(File.DirApp,Codebase.PGSETINI)=True Then
        'hálózatban minden munkaállomáson be kell állítani egyszer a db ip címét!
        dbinimap = File.ReadMap(File.DirApp,Codebase.PGSETINI)
        Try
            If dbinimap.IsInitialized=True Then
                If dbinimap.ContainsKey("backupexepath")=True Then
                    bep = dbinimap.Get("backupexepath")  '<---- error happened here (in debug and release mode too)
                End If
            End If
        Catch
            bep = ""
        End Try
    End If
    If bep.Length = "" Then <---- error was here: this is why was mentioned numberformat and empty string. when I correct this, all error disappeared!!!!
thank you for all who helped to reveal the reason!

*****************************************************
but why was signaled a good line as erroneous and a
wrong line as good?
*****************************************************
 
Last edited:
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
you never showed us this before:
B4X:
    If bep.Length = "" Then <---- error was here: this is why was mentioned numberformat and empty string. when I correct here, all error disappe

we would have said something much sooner.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Just for testing purposes, put the error back in, do a Tools->Clean Project and re-run it to see if it changes the error location
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
I did it conscientiously. Cleaned the project.
The line "If bep.Length = "" Then" makes happen an error in much previous line "bep = dbinimap.Get("backupexepath")" !
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
I was stupid (again), but in the debug mode the program exited there. The mistake (lower!):
B4X:
    If bep.Length = "" Then <---- error was here: this is why was mentioned numberformat and empty string. when I correct this, all error disappeared!!!!
but why was signaled a good line as erroneous and a wrong line as good?

A better why question is: why are you comparing a number to a string?

Why not:
B4X:
    If bep.Length = 0 Then
 
Upvote 0

rosippc64a

Active Member
Licensed User
Longtime User
A better why question is: why are you comparing a number to a string?

Why not:
B4X:
    If bep.Length = 0 Then
obviously not intentionally, but in the same time I modify multiple program lines and my attention was captured other inportant things, so it remains as erroneous.
After that I was mislead by the errors, happened here
B4X:
If dbinimap.ContainsKey("bexepath")=True Then '<----- java.lang.NumberFormatException: empty String
                    backupexepath = "" & dbinimap.Get("bexepath")
what was so surprizing, that my eyes can't go next.
 
Upvote 0
Top