B4J Question list (own Type) record problem with randomaccessfile

Tayfur

Well-Known Member
Licensed User
Longtime User
Hello;


ı HAVE PROBLEM WİTH RANDOMACCESSFİLE.
First record is OK. But First record damged when second record added it. And first record separet 3 parts.

Adsız.png


B4X:
Type PERSONEL (TamAd As String,User As String,Pass As String, Yetkilistesi As Map)
    Public PERSONEL As List

Load code:
B4X:
Dim r As RandomAccessFile
    r.Initialize(Main.AYAR.DirPersonel,Main.AYAR.FPersonel, False)
    Log(r.Size)
    If r.Size>0 Then
        Dim res As Object=r.ReadB4XObject(0)
        Main.PERSONEL= res
    End If
    r.Close

Save code:
B4X:
Dim r As RandomAccessFile
            r.Initialize(Main.AYAR.DirPersonel,Main.AYAR.FPersonel, False)
            r.WriteB4XObject(Main.PERSONEL, 0)
            r.Close
 

Tayfur

Well-Known Member
Licensed User
Longtime User
Why aren't you using KVS2? It will be simpler.

I don't see where you are saving more than one object.

seen on the picture;
first object in 0-1-2 (its damged and divided, i cant understandt)
second object in 3

KVS2; I see first time. And I will look.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
B4X:
r.WriteB4XObject(Main.PERSONEL, 0)

You are writing at position 0 each time, it will write at the beginning of the file, overwriting what is already there with as much data as the write contains.

Using a RandomAccess file in this way means that you will need to keep an index of where each record is stored so that you can retrieve it. You should still consider using KVS2 it's a much simpler solution, or even SQLite directly if you want to search to retrieve the records..
 
Last edited:
Upvote 0

Tayfur

Well-Known Member
Licensed User
Longtime User
Are you able to reproduce it in a small project?
Are you able to reproduce it in a small project?

I made a foolish mistake.I don't know what it is. I made a simple example, but Its worked.
I erased the code and rewritten it.
Sometimes I must rewrite code more simple.

Thanks.
therefore I learned Key Value Store.
 
Upvote 0
Top