B4J Question java.lang.OutOfMemoryError: Java heap space

schimanski

Well-Known Member
Licensed User
Longtime User
I always get the following exception, when I try to downoad and save an encrypted file:

java.lang.RuntimeException: java.lang.RuntimeException: java.lang.OutOfMemoryError: Java heap space

This is my file on the server:
B4X:
Dim Kontaktdatei As RandomAccessFile
Kontaktdatei.Initialize(File.DirApp, "EIS/Kontakte/Kontakte.eis", False)
Kontaktdatei.WriteEncryptedObject(Main.Kontakte, Main.CopyrightString, 0)
Kontaktdatei.Close


and it seems, that it is not possible to save this file with openoutput:

B4X:
Sub JobDone (Job As HttpJob)
    
        If Job.Success=True Then
            Select Job.JobName
                Case "Kontakte"
              
                    Dim out As OutputStream
                    out=File.OpenOutput(File.DirApp, "Kontakte.eis", False)
                    File.Copy2(Job.GetInputStream, out)
                    out.Close
                ....
        .....
 

schimanski

Well-Known Member
Licensed User
Longtime User
B4X:
Program started.
Kontakte vom EIS-Server geladen!
main._kontaktelokal_laden (java line: 633)
java.lang.OutOfMemoryError: Java heap space
    at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.readHelper(RandomAccessFile.java:382)
    at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.ReadEncryptedObject(RandomAccessFile.java:377)
    at de.sekutor.eis_desktop.main._kontaktelokal_laden(main.java:633)
    at de.sekutor.eis_desktop.main._jobdone(main.java:552)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:483)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:446)
    at anywheresoftware.b4a.keywords.Common.access$0(Common.java:426)
    at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:500)
    at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:301)
    at com.sun.javafx.application.PlatformImpl$6$1.run(PlatformImpl.java:298)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl$6.run(PlatformImpl.java:298)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.access$300(WinApplication.java:39)
    at com.sun.glass.ui.win.WinApplication$4$1.run(WinApplication.java:112)
    at java.lang.Thread.run(Thread.java:745)

Don't know the exact line, because I have to start in release-mode. The exception is raised, when I add the lines above!
 
Upvote 0

schimanski

Well-Known Member
Licensed User
Longtime User
The problem seems to be when i try to open the file direct after download!

B4X:
Dim out As OutputStream
out=File.OpenOutput(File.DirApp, "Kontakte.eis", False)
File.Copy2(Job.GetInputStream, out)
out.Close

If File.Exists(File.DirApp, "Kontakte.eis") Then
        Dim Kontaktdatei As RandomAccessFile
        Kontaktdatei.Initialize(File.DirApp, "Kontakte.eis", False)
        Kontakte = Kontaktdatei.ReadEncryptedObject(CopyrightString,0)
        Kontaktdatei.Close
 Else
        Kontakte.Initialize
 End If
 
Upvote 0

schimanski

Well-Known Member
Licensed User
Longtime User
B4X:
Dim Kontaktdatei As RandomAccessFile
Kontaktdatei.Initialize(File.DirApp, "Kontakte.eis", False)
Kontaktdatei.WriteEncryptedObject(Main.Kontakte, Main.CopyrightString, 0)
Kontaktdatei.Close
 
Upvote 0

schimanski

Well-Known Member
Licensed User
Longtime User
I create the file in b4j, but it is no problem, to download and read it in b4a.
I create the file with the b4j Server and download it with different clients in b4a and b4j. I can download the file or read the file in my b4j client, but both raise the exception...

I have checked something:
Wenn i copy the file manuell, i can open it in b4j. It seems, that the outputstream after downloading corrupt the file.

I use a very similar code in b4a...No problem
 
Last edited:
Upvote 0

schimanski

Well-Known Member
Licensed User
Longtime User
Sorry for those circumstances. I forgot the parameter in the downloadlink and the server sends me a wrong request...:confused:
It is running, now...
 
Upvote 0
Top