Android Question possible bug in ReadB4XObject in B4A

Branko Milosevic

Active Member
Licensed User
I have two identical pieces of code in B4A and B4i writing a List object to a random access file via WriteB4XObject

File written with B4A WriteB4XObject is readable with both B4i and B4A ReadB4XObject

File written with B4i WriteB4XObject is readable only with B4i and crashes when attempting to read with B4A

Error occurred on B4A line:
B4X:
129         CurrentFileList=raf.ReadB4XObject(0)
Here is the error log from B4A:
Error occurred on line: 129 (CurrentSession)
java.lang.RuntimeException: java.lang.ClassNotFoundException: com.impromptusports.impromptuhoops.main$_sessionsettings
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readType(B4XSerializator.java:297)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readObject(B4XSerializator.java:357)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readList(B4XSerializator.java:246)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readObject(B4XSerializator.java:345)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ReadObject(B4XSerializator.java:112)
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.ReadB4XObject(RandomAccessFile.java:323)
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:339)
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:134)
at com.impromptusports.impromptuhoops.currentsession.afterFirstLayout(currentsession.java:102)
at com.impromptusports.impromptuhoops.currentsession.access$000(currentsession.java:17)
at com.impromptusports.impromptuhoops.currentsession$WaitForLayout.run(currentsession.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:135)
at android.app.ActivityThread.main(ActivityThread.java:5254)
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:903)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Caused by: java.lang.ClassNotFoundException: com.impromptusports.impromptuhoops.main$_sessionsettings
at java.lang.Class.classForName(Native Method)
at java.lang.Class.forName(Class.java:309)
at java.lang.Class.forName(Class.java:273)
at anywheresoftware.b4a.randomaccessfile.RandomAccessFile.readTypeClass(RandomAccessFile.java:562)
at anywheresoftware.b4a.randomaccessfile.B4XSerializator.readType(B4XSerializator.java:274)
... 24 more
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.impromptusports.impromptuhoops.main$_sessionsettings" on path: DexPathList[[zip file "/data/app/com.impromptusports.impromptuhoops-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
... 29 more
Suppressed: java.lang.ClassNotFoundException: com.impromptusports.impromptuhoops.main$_sessionsettings
at java.lang.Class.classForName(Native Method)
at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
... 30 more
Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available

I uploaded two files one created with iOS and one with Android. They both contain the same object (a List in this case).

Androidmade.txt is readable on both OS.
iOSmade.txt is readable only on iOS.

Note that these are not text files, I had to use txt extension to upload files here.
 

Attachments

  • androidmade.txt
    239 bytes · Views: 186
  • iOSmade.txt
    207 bytes · Views: 189

DonManfred

Expert
Licensed User
Longtime User
it would help if you post a small example project(b4a+b4i) which create these files.
 
Upvote 0

Branko Milosevic

Active Member
Licensed User
Here is the code to create the files:

B4X:
Sub Process_globals
Type SessionSettings (Time As Int, Tempo As Int, PGfactor As Int)
Type ClvValue (ExerciseID As Int,Frequency As Double,Time As Double,ExerciseText As String,PriorityGroup As Boolean,VideoAvailable As Boolean, selected As Boolean,code As String)
End Sub


Sub Activity_Create(firsttime As Boolean)
     create_untitled
End Sub

Sub create_untitled()
    Dim Session As SessionSettings  'custom type
    Dim exercise As ClvValue           'custom type

    Dim raf As RandomAccessFile
    Dim NewList As List
    NewList.Initialize

'assigning values to custom type Session members
    Session.Time=10     
    Session.Tempo=70
    Session.PGfactor=5

'adding Session object to the List
    NewList.Add(Session)

'assigning values to custom type Exercise members
     exercise.ExerciseID = 1
      exercise.Frequency = 5
     exercise.Time= 2
      exercise.ExerciseText = "One"
       exercise.PriorityGroup = True
       exercise.VideoAvailable = False
       exercise.selected = True
       exercise.code = ""

'adding Exercise object to the list
        NewList.Add(Exercise)
   
'writing the NewList to the file
    raf.initialize(File.DirRootExternal&"/impromptu","untitled.imp",False)
    raf.WriteB4XObject(NewList,0)
    raf.Close
End Sub

To read:
B4X:
Sub ReadList()
   Dim NewList as List
   Dim raf As RandomAccessFile
   NewList.Initialize
    raf.initialize(File.DirRootExternal&"/impromptu","untitled.imp",False)
   
        If raf.Size>0 Then 
        NewList=raf.ReadB4XObject(0)  'fails here to read with B4A if the above code to create the file is compiled with B4i
            raf.Close

Endsub
 
Upvote 0

Branko Milosevic

Active Member
Licensed User
No, the types were in another module. I moved them to the main and it's ok now.
I am guessing in B4i it doesn't need to be in the main?
 
Last edited:
Upvote 0
Top