Android Question RandomAccesFiles java.lang.NullPointerException

Discussion in 'Android Questions' started by Firpas, Feb 4, 2015.

  1. Firpas

    Firpas Active Member Licensed User

    Hi to everybody:

    I'working with RandomAccessFiles and WriteEncryptedObject / ReadEncryptedObject and i have this error:

    And this is my code:

    Code:
    Sub Process_Globals
    Dim ColorSondas() As Int = Array As Int(0xFF0000FF0xFF00C0000xFF00C0C00xFFC0C0000xFFC040000xFFC000C00xFFC000000xFFFF80000xFFFF00000xFF80FFFF0xFF8080800xFF8080000xFFFFFF000xFF8080FF0xFFFF80FF0xFF80FF800xFF8FBC8B0xFFFF00FF0xFF483D8B0xFF6495ED)
    ....
    End Sub

    Sub Config_Save As Boolean
        
    Try
            
    File.WriteMap(File.DirInternal, "Config.txt", Config)
         
            
    Dim Config2 As Map
            Config2.Initialize
            
    If File.Exists(DataDir, "Config.dat"AND File.Size(DataDir, "Config.dat") > 0 Then Then
                
    Dim Raf As RandomAccessFile
                Raf.Initialize(DataDir, 
    "Config.dat"False)
                Config2 = Raf.ReadEncryptedObject(
    "agsystem", Raf.CurrentPosition)
                Raf.Close
            
    End If
                         
            
    For Each Key As String In Config.Keys
                Config2.Put(Key, Config.Get(Key))
            
    Next
         
            
    Dim Raf2 As RandomAccessFile
            Raf2.Initialize(DataDir, 
    "Config.dat"False)
           
    'The next sentence is the cause of the error
            Raf2.WriteEncryptedObject(Config2, "secret", Raf.CurrentPosition)
            Raf2.Close
            
    Return True
        
    Catch
            
    Log(LastException)
            
    Return False
        
    End Try
    End Sub
    I want to save a Map and one key contains an array of 20 elements (int).
    Can this be the cause? How do I fix it?

    What i'm doing wrong??

    Thanks
     
    Last edited: Feb 4, 2015
  2. thedesolatesoul

    thedesolatesoul Expert Licensed User

    Code:
    Raf2.WriteEncryptedObject(Config2, "secret", Raf.CurrentPosition)
    Use Raf2.CurrentPosition instead.
     
    NJDude likes this.
  3. HotShoe

    HotShoe Well-Known Member Licensed User

    Also lose the second Then in the above line.

    --- Jem
     
    thedesolatesoul likes this.
  4. Firpas

    Firpas Active Member Licensed User

    Hi the both:

    I'm embarrassed by my error.

    thanks for your cooperation.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice