Android Question KeyValueStore GetObject returns Null

Discussion in 'Android Questions' started by jhagerup, Aug 11, 2015.

  1. jhagerup

    jhagerup Member Licensed User

    Code:
    'Class module myClass
    Sub Class_Globals
        
    Dim mVar As String   
    End Sub

    Public Sub Initialize
        mVar = 
    "testing"
    End Sub

    public Sub getVar As String
        
    Return mVar
    End Sub


    Sub Activity_Create(FirstTime As Boolean)
        kvs.Initialize(
    File.DirDefaultExternal,"test")
        
    Dim myObject As myClass
        myObject.Initialize
        
    Log (myObject.Var)
        kvs.PutObject(
    "1", myObject)
        
    Log(kvs.ContainsKey("1"))
        
    Dim myObject2 As myClass
        myObject2 = kvs.GetObject(
    "1")
        
    Log(myObject2.Var)
    End Sub
    Log:
    ** Activity (main) Create, isFirst = true **
    testing
    true
    Error occurred on line: 38 (KeyValueStore)
    java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String b4a.example.myclass._getvar(b4a.example.myclass)' on a null object reference
    at b4a.example.main._activity_create(main.java:375)
    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:636)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:305)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
    at b4a.example.main.afterFirstLayout(main.java:100)
    at b4a.example.main.access$100(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:78)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:155)
    at android.app.ActivityThread.main(ActivityThread.java:5696)
    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:1028)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:823)
    ** Activity (main) Resume **


    Works perfectly in B4i !

    Any suggestions ?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Can you create a small project with this code and upload it?
     
  3. jhagerup

    jhagerup Member Licensed User

    Yes, here it is.
     

    Attached Files:

  4. Erel

    Erel Administrator Staff Member Licensed User

    It is very simple. You cannot store class instances with KVS.

    Supports types: Lists, Arrays, Maps, Strings, primitive types and user defined types.
     
  5. jhagerup

    jhagerup Member Licensed User

    Thanks.
    I'm developing in B4i and B4A simultaneously and as it worked in B4i I thougt that it would work in B4A too ;-(
     

    Attached Files:

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