Android Question randomaccessfile.RandomAccessFile.ReadInt(RandomAccessFile.java:137)

Franck Danard

Member
Licensed User
Longtime User
Hi

I've got this issue this morning day.
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.ReadInt(RandomAccessFile.java:137)
It worked fine yesterday evening.

B4X:
    LoadSettings( File.DirInternal, "settings.conf")

    .../...

    Sub LoadSettings( Dir As String, FileName As String)
       If Dir="" Or FileName="" Then
           Msgbox( "Empty Dir or FileName","error")
           Return
       End If
       Dim raf As RandomAccessFile
       raf.Initialize( Dir, FileName, False)
       SettingsMap = raf.ReadEncryptedObject( "123456", raf.CurrentPosition) <---- Crach here.
     
       raf.Close
    End Sub

Any idea?
 

Franck Danard

Member
Licensed User
Longtime User
B4X:
Logger connecté à:  samsung SM-J320FN
--------- beginning of main
--------- beginning of system
Copying updated assets files (4)
** Activity (main) Create, isFirst = true **
Error occurred on line: 152 (Main)
java.nio.BufferUnderflowException
   at java.nio.DirectByteBuffer.getInt(DirectByteBuffer.java:230)
   at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.ReadInt(RandomAccessFile.java:137)
   at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.readHelper(RandomAccessFile.java:406)
   at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.ReadEncryptedObject(RandomAccessFile.java:403)
   at b4a.example.main._loadsettings(main.java:426)
   at b4a.example.main._activity_create(main.java:390)
   at java.lang.reflect.Method.invoke(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
   at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
   at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
   at java.lang.reflect.Method.invoke(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
   at b4a.example.main.afterFirstLayout(main.java:102)
   at b4a.example.main.access$000(main.java:17)
   at b4a.example.main$WaitForLayout.run(main.java:80)
   at android.os.Handler.handleCallback(Handler.java:739)
   at android.os.Handler.dispatchMessage(Handler.java:95)
   at android.os.Looper.loop(Looper.java:145)
   at android.app.ActivityThread.main(ActivityThread.java:6934)
   at java.lang.reflect.Method.invoke(Native Method)
   at java.lang.reflect.Method.invoke(Method.java:372)
   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)
** Activity (main) Resume **
Copying updated assets files (4)
 
Upvote 0

Franck Danard

Member
Licensed User
Longtime User
Hmm.
I don't understand anything.

I check if the file exist and i enabled the writing on the file and now i've got an error.
B4X:
raf.WriteEncryptedObject( SettingsMap, "123456", raf.CurrentPosition)

Give this error!

B4X:
Logger connecté à:  samsung SM-J320FN
--------- beginning of main
--------- beginning of system
Copying updated assets files (4)
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
Error occurred on line: 179 (Main)
java.lang.RuntimeException: Object should first be initialized (Map).
    at anywheresoftware.b4a.AbsObjectWrapper.getObject(AbsObjectWrapper.java:50)
    at b4a.example.main._savesettings(main.java:777)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:5246)
    at android.widget.TextView.performClick(TextView.java:10618)
    at android.view.View$PerformClick.run(View.java:21256)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:6934)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1404)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1199)

I wondered if there's no problem with the IDE and the code pushed on the mobile.
Sometimes i change the code, and i've got the same result.
If i close B4A, i uninstall my project and re-open this one, the code seems good or not (but there's some changes anyway).
I've a real doubt about the real changes and app running on my mobile.
Sometimes i feel that's a early version and not the one with the real changes.
Weird anyway.

This is for this reason that's pretty confuse.
 
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Longtime User
java.lang.RuntimeException: Object should first be initialized (Map).

If i close B4A, i uninstall my project and re-open this one, the code seems good or not (but there's some changes anyway).
Unistall the project and re-open it doesn't help you. There is not a bug in the IDE. The error is explained: You need to inizialize the map (SettingMap that you are passing in raf.WriteEncryptedObject)
 
Upvote 0
Top