Android Question how to get the list of kvs KeyValueStore on a loop

omarruben

Active Member
Licensed User
Longtime User
B4X:
    ' store locally
    xui.SetDataFolder("kvs")
    kvs.Initialize(xui.DefaultFolder, "kvs.dat")

B4X:
Dim tempList As List
tempList = kvs.ListKeys

trying to get al keys, but a have an error:

"java.lang.RuntimeException: Class instance was not initialized (keyvaluestore)"

I am looking to interact on a loop with all returned keys.. but no luck
 

omarruben

Active Member
Licensed User
Longtime User
still not working and I have this error, after the code :
B4X:
private Sub loadCustomeChannels
    Dim tempList As List
    tempList.initialize
   
   
   
    For Each key As String In kvs.ListKeys   -[B]---> (line 207)[/B]
    '    Dim value As Object = kvs.Get(key)
    ''    Log( "key: " & key )
    '    Log( value )
    Next
   
   
    'totalChannels = 0
    'For Each title As String In tempList
'                      
        'listaChannels(totalChannels).title = title
        'listaChannels(totalChannels).address = kvs.Get(title)
        'totalChannels = totalChannels + 1
    'Next
   
End Sub

** Activity (main) Resume **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Error occurred on line: 207 (B4XMainPage)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:1087)
at hightechstream.rufusiptv.b4xpagesmanager._createpageifneeded(b4xpagesmanager.java:1069)
at hightechstream.rufusiptv.b4xpagesmanager._showpage(b4xpagesmanager.java:426)
at hightechstream.rufusiptv.b4xpagesmanager._addpage(b4xpagesmanager.java:246)
at hightechstream.rufusiptv.b4xpagesmanager._addpageandcreate(b4xpagesmanager.java:260)
at hightechstream.rufusiptv.b4xpagesmanager._initialize(b4xpagesmanager.java:166)
at hightechstream.rufusiptv.main._activity_create(main.java:416)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at hightechstream.rufusiptv.main.afterFirstLayout(main.java:105)
at hightechstream.rufusiptv.main.access$000(main.java:17)
at hightechstream.rufusiptv.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:978)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loopOnce(Looper.java:238)
at android.os.Looper.loop(Looper.java:357)
at android.app.ActivityThread.main(ActivityThread.java:8090)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1026)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:336)
at anywheresoftware.b4a.debug.Debug.CallSubNew2(Debug.java:285)
... 25 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:318)
... 26 more
Caused by: java.lang.RuntimeException: Class instance was not initialized (keyvaluestore)
at anywheresoftware.b4a.debug.Debug.shouldDelegate(Debug.java:242)
at hightechstream.rufusiptv.keyvaluestore._listkeys(keyvaluestore.java:80)
at hightechstream.rufusiptv.b4xmainpage._loadcustomechannels(b4xmainpage.java:139)
at hightechstream.rufusiptv.b4xmainpage._b4xpage_created(b4xmainpage.java:101)
... 28 more
** Activity (main) Resume **
 
Upvote 0

Mariano Ismael Castro

Active Member
Licensed User
still not working and I have this error, after the code :
B4X:
private Sub loadCustomeChannels
    Dim tempList As List
    tempList.initialize
  
  
  
    For Each key As String In kvs.ListKeys   -[B]---> (line 207)[/B]
    '    Dim value As Object = kvs.Get(key)
    ''    Log( "key: " & key )
    '    Log( value )
    Next
  
  
    'totalChannels = 0
    'For Each title As String In tempList
'                     
        'listaChannels(totalChannels).title = title
        'listaChannels(totalChannels).address = kvs.Get(title)
        'totalChannels = totalChannels + 1
    'Next
  
End Sub

** Activity (main) Resume **
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create (first time) **
Error occurred on line: 207 (B4XMainPage)
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.keywords.Common.CallSubDebug2(Common.java:1087)
at hightechstream.rufusiptv.b4xpagesmanager._createpageifneeded(b4xpagesmanager.java:1069)
at hightechstream.rufusiptv.b4xpagesmanager._showpage(b4xpagesmanager.java:426)
at hightechstream.rufusiptv.b4xpagesmanager._addpage(b4xpagesmanager.java:246)
at hightechstream.rufusiptv.b4xpagesmanager._addpageandcreate(b4xpagesmanager.java:260)
at hightechstream.rufusiptv.b4xpagesmanager._initialize(b4xpagesmanager.java:166)
at hightechstream.rufusiptv.main._activity_create(main.java:416)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:157)
at hightechstream.rufusiptv.main.afterFirstLayout(main.java:105)
at hightechstream.rufusiptv.main.access$000(main.java:17)
at hightechstream.rufusiptv.main$WaitForLayout.run(main.java:83)
at android.os.Handler.handleCallback(Handler.java:978)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loopOnce(Looper.java:238)
at android.os.Looper.loop(Looper.java:357)
at android.app.ActivityThread.main(ActivityThread.java:8090)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1026)
Caused by: java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:336)
at anywheresoftware.b4a.debug.Debug.CallSubNew2(Debug.java:285)
... 25 more
Caused by: java.lang.reflect.InvocationTargetException
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.debug.Debug.CallSub4(Debug.java:318)
... 26 more
Caused by: java.lang.RuntimeException: Class instance was not initialized (keyvaluestore)
at anywheresoftware.b4a.debug.Debug.shouldDelegate(Debug.java:242)
at hightechstream.rufusiptv.keyvaluestore._listkeys(keyvaluestore.java:80)
at hightechstream.rufusiptv.b4xmainpage._loadcustomechannels(b4xmainpage.java:139)
at hightechstream.rufusiptv.b4xmainpage._b4xpage_created(b4xmainpage.java:101)
... 28 more
** Activity (main) Resume **
Your problem is strange, I attached a small example (I hope it works for you), I have tested it in B4J and B4A... It works fine
What occurs to me is that maybe you are using KeyValueStore2 instead of KeyValueStore
 

Attachments

  • KVS_Test.zip
    13.7 KB · Views: 53
Upvote 0

omarruben

Active Member
Licensed User
Longtime User
Your problem is strange, I attached a small example (I hope it works for you), I have tested it in B4J and B4A... It works fine
What occurs to me is that maybe you are using KeyValueStore2 instead of KeyValueStore
thank you for your answer, I am using the correct KeyvalueStore (not the one that ends in 2)
nothing still the error
I may try to move to sqlite or save the data on a server
 
Upvote 0

omarruben

Active Member
Licensed User
Longtime User
this is a screenshot of the full message
 

Attachments

  • 2023-09-10 09_31_39-Window.jpg
    2023-09-10 09_31_39-Window.jpg
    78.2 KB · Views: 42
Upvote 0

Mahares

Expert
Licensed User
Longtime User
@Erel can you give some ideas please, thank you
1. When you ask only one person to help you, you make evryone else unimportant and irrelevant, especially the ones that tried to help you.
2. Don't post your error message as screenshot. Post it as text. Red text on black background is not easy to read.
3. You were offered several answers. If none helped you, then the only thing left for you to do is post your project or a small project that demonstrates the issue.
 
Upvote 0

omarruben

Active Member
Licensed User
Longtime User
1. When you ask only one person to help you, you make evryone else unimportant and irrelevant, especially the ones that tried to help you.
2. Don't post your error message as screenshot. Post it as text. Red text on black background is not easy to read.
3. You were offered several answers. If none helped you, then the only thing left for you to do is post your project or a small project that demonstrates the issue.
Thank you for your toughs.
My intentions are good.. I always say THANK YOU to everybody willing to help .
I refer to EREL because we like it or not he is the one who always answers the hard questions.
We love B4X and we love all the community regardless the experience.
 
Upvote 0

Lucas Siqueira

Active Member
Licensed User
Longtime User
this is a screenshot of the full message

According to the error, kvs was not started.

Maybe in the part where you are trying to get the kvs keys, you haven't started kvs yet.

Make sure you are using the latest version of keyValueStore.
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
I am very surprised and astonished !
You got an answer with a small test project in post #5!
Did you test it ?
I tested it and it works with B4J and B4A !
I am afraid that you did NOT test it, why ?
From the error message it seems that you did not initialize kvs somewhere, did you look at this ?
You need to read carefully the answers you get, look at test projects you get, and look at differences with your project !
You do not provide all the code you use, and therefore the helpers need to guess what you could have done wrong.
It would be much more efficient if YOU posted either your project or better a small project showing the problem.
 
Upvote 0

omarruben

Active Member
Licensed User
Longtime User
According to the error, kvs was not started.

Maybe in the part where you are trying to get the kvs keys, you haven't started kvs yet.

Make sure you are using the latest version of keyValueStore.
thank you for your help
 
Upvote 0
Top