Sergey_New Well-Known Member Licensed User Longtime User Feb 9, 2025 #1 I used kvs this: B4X: Copy Starter.kvs.PutBitmap(id,bmp) Now I need to additionally save another string parameter in kvs. How can I do it?
I used kvs this: B4X: Copy Starter.kvs.PutBitmap(id,bmp) Now I need to additionally save another string parameter in kvs. How can I do it?
teddybear Well-Known Member Licensed User Feb 9, 2025 #2 What do you mean? save another string parameter with same id in kvs? Upvote 0
MicroDrie Well-Known Member Licensed User Longtime User Feb 9, 2025 #3 See [B4X] KVS - KeyValueStore library Upvote 0
Sergey_New Well-Known Member Licensed User Longtime User Feb 9, 2025 #4 teddybear said: What do you mean? Click to expand... I need to pass and receive three parameters from kvs at once. Upvote 0
teddybear said: What do you mean? Click to expand... I need to pass and receive three parameters from kvs at once.
MicroDrie Well-Known Member Licensed User Longtime User Feb 9, 2025 #5 Sergey_New said: I need to pass and receive three parameters from kvs at once. Click to expand... Define a type with your thee parameters, fill the type with your thee parameters, write the thee parameters as type to and retrieve the three parameters in the type at once from the kvs. Be awere that you can only have one time use the same type name definition for all B4XPages in B4XPage environment were the defined type name can access in all B4XPages separate from B4XPage where the type is defined. Upvote 0
Sergey_New said: I need to pass and receive three parameters from kvs at once. Click to expand... Define a type with your thee parameters, fill the type with your thee parameters, write the thee parameters as type to and retrieve the three parameters in the type at once from the kvs. Be awere that you can only have one time use the same type name definition for all B4XPages in B4XPage environment were the defined type name can access in all B4XPages separate from B4XPage where the type is defined.
Sergey_New Well-Known Member Licensed User Longtime User Feb 9, 2025 #6 MicroDrie said: Define a type with your thee parameters Click to expand... B4X: Copy ' Type myTipe(id As String, bmp As Bitmap, s As String) Dim t As myTipe t.Initialize t.id="a" t.bmp=LoadBitmap(File.DirAssets, "arrow.png") t.s="x" Starter.kvs.Initialize(Starter.myFolder, "kvs.dat") Starter.kvs.Put("i", t) There is an error on the last line of code. How to add myTipe correctly? Spoiler: error Error occurred on line: 18 (KeyValueStore) java.lang.RuntimeException: java.lang.RuntimeException: Cannot serialize object: android.graphics.Bitmap@5965602 at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:285) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:241) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.WriteObject(B4XSerializator.java:121) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ConvertObjectToBytes(B4XSerializator.java:79) at sv.bystrovzorov.keyvaluestore._put(keyvaluestore.java:93) 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 anywheresoftware.b4a.debug.Debug.delegate(Debug.java:265) at sv.bystrovzorov.function._setminiatures(function.java:7654) at sv.bystrovzorov.mainmenu$ResumableSub_Activity_Create.resume(mainmenu.java:518) at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48) 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 anywheresoftware.b4a.BA.raiseEvent2(BA.java:205) at anywheresoftware.b4a.BA.raiseEvent(BA.java:201) at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43) at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1748) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7884) 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:936) Caused by: java.lang.RuntimeException: Cannot serialize object: android.graphics.Bitmap@5965602 at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:275) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:241) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeMap(B4XSerializator.java:256) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:283) ... 30 more Last edited: Feb 9, 2025 Upvote 0
MicroDrie said: Define a type with your thee parameters Click to expand... B4X: Copy ' Type myTipe(id As String, bmp As Bitmap, s As String) Dim t As myTipe t.Initialize t.id="a" t.bmp=LoadBitmap(File.DirAssets, "arrow.png") t.s="x" Starter.kvs.Initialize(Starter.myFolder, "kvs.dat") Starter.kvs.Put("i", t) There is an error on the last line of code. How to add myTipe correctly? Spoiler: error Error occurred on line: 18 (KeyValueStore) java.lang.RuntimeException: java.lang.RuntimeException: Cannot serialize object: android.graphics.Bitmap@5965602 at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:285) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:241) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.WriteObject(B4XSerializator.java:121) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ConvertObjectToBytes(B4XSerializator.java:79) at sv.bystrovzorov.keyvaluestore._put(keyvaluestore.java:93) 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 anywheresoftware.b4a.debug.Debug.delegate(Debug.java:265) at sv.bystrovzorov.function._setminiatures(function.java:7654) at sv.bystrovzorov.mainmenu$ResumableSub_Activity_Create.resume(mainmenu.java:518) at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48) 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 anywheresoftware.b4a.BA.raiseEvent2(BA.java:205) at anywheresoftware.b4a.BA.raiseEvent(BA.java:201) at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43) at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1748) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7884) 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:936) Caused by: java.lang.RuntimeException: Cannot serialize object: android.graphics.Bitmap@5965602 at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:275) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:241) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeMap(B4XSerializator.java:256) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:283) ... 30 more
teddybear Well-Known Member Licensed User Feb 9, 2025 #7 Sergey_New said: B4X: Copy ' Type myTipe(id As String, bmp As Bitmap, s As String) Dim t As myTipe t.Initialize t.id="a" t.bmp=LoadBitmap(File.DirAssets, "arrow.png") t.s="x" Starter.kvs.Initialize(Starter.myFolder, "kvs.dat") Starter.kvs.Put("i", t) There is an error on the last line of code. How to add myTipe correctly? Spoiler: error Error occurred on line: 18 (KeyValueStore) java.lang.RuntimeException: java.lang.RuntimeException: Cannot serialize object: android.graphics.Bitmap@5965602 at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:285) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:241) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.WriteObject(B4XSerializator.java:121) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ConvertObjectToBytes(B4XSerializator.java:79) at sv.bystrovzorov.keyvaluestore._put(keyvaluestore.java:93) 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 anywheresoftware.b4a.debug.Debug.delegate(Debug.java:265) at sv.bystrovzorov.function._setminiatures(function.java:7654) at sv.bystrovzorov.mainmenu$ResumableSub_Activity_Create.resume(mainmenu.java:518) at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48) 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 anywheresoftware.b4a.BA.raiseEvent2(BA.java:205) at anywheresoftware.b4a.BA.raiseEvent(BA.java:201) at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43) at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1748) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7884) 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:936) Caused by: java.lang.RuntimeException: Cannot serialize object: android.graphics.Bitmap@5965602 at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:275) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:241) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeMap(B4XSerializator.java:256) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:283) ... 30 more Click to expand... The object by kvs put can only be or contain primitive type. bitmap is non-primitive type, you only use putbitmap method. if you want to use type to put, you need to convert bitmap to an array of byte. Upvote 0
Sergey_New said: B4X: Copy ' Type myTipe(id As String, bmp As Bitmap, s As String) Dim t As myTipe t.Initialize t.id="a" t.bmp=LoadBitmap(File.DirAssets, "arrow.png") t.s="x" Starter.kvs.Initialize(Starter.myFolder, "kvs.dat") Starter.kvs.Put("i", t) There is an error on the last line of code. How to add myTipe correctly? Spoiler: error Error occurred on line: 18 (KeyValueStore) java.lang.RuntimeException: java.lang.RuntimeException: Cannot serialize object: android.graphics.Bitmap@5965602 at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:285) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:241) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.WriteObject(B4XSerializator.java:121) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.ConvertObjectToBytes(B4XSerializator.java:79) at sv.bystrovzorov.keyvaluestore._put(keyvaluestore.java:93) 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 anywheresoftware.b4a.debug.Debug.delegate(Debug.java:265) at sv.bystrovzorov.function._setminiatures(function.java:7654) at sv.bystrovzorov.mainmenu$ResumableSub_Activity_Create.resume(mainmenu.java:518) at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resumeAsUserSub(DebugResumableSub.java:48) 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 anywheresoftware.b4a.BA.raiseEvent2(BA.java:205) at anywheresoftware.b4a.BA.raiseEvent(BA.java:201) at anywheresoftware.b4a.shell.DebugResumableSub$DelegatableResumableSub.resume(DebugResumableSub.java:43) at anywheresoftware.b4a.keywords.Common$14.run(Common.java:1748) at android.os.Handler.handleCallback(Handler.java:942) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7884) 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:936) Caused by: java.lang.RuntimeException: Cannot serialize object: android.graphics.Bitmap@5965602 at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:275) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeObject(B4XSerializator.java:241) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeMap(B4XSerializator.java:256) at anywheresoftware.b4a.randomaccessfile.B4XSerializator.writeType(B4XSerializator.java:283) ... 30 more Click to expand... The object by kvs put can only be or contain primitive type. bitmap is non-primitive type, you only use putbitmap method. if you want to use type to put, you need to convert bitmap to an array of byte.
MicroDrie Well-Known Member Licensed User Longtime User Feb 9, 2025 #8 teddybear said: if you want to use type to put, you need to convert bitmap to an array of byte. Click to expand... Or convert it to base64 string Reduce image size before encoding, preferably without writing to disk. Edit: link updated Last edited: Feb 9, 2025 Upvote 0
teddybear said: if you want to use type to put, you need to convert bitmap to an array of byte. Click to expand... Or convert it to base64 string Reduce image size before encoding, preferably without writing to disk. Edit: link updated
Sergey_New Well-Known Member Licensed User Longtime User Feb 9, 2025 #9 MicroDrie said: Reduce image size before encoding, preferably without writing to disk. Click to expand... The link is not working, please fix it. Upvote 0
MicroDrie said: Reduce image size before encoding, preferably without writing to disk. Click to expand... The link is not working, please fix it.
MicroDrie Well-Known Member Licensed User Longtime User Feb 9, 2025 #10 Sergey_New said: The link is not working, please fix it. Click to expand... Done as requested. Upvote 0
Sergey_New Well-Known Member Licensed User Longtime User Feb 9, 2025 #11 teddybear, MicroDrie thanks! Unfortunately too many transformations will take a significant amount of time when filling kvs with more than 200 images. I will try other methods. Upvote 0
teddybear, MicroDrie thanks! Unfortunately too many transformations will take a significant amount of time when filling kvs with more than 200 images. I will try other methods.
MicroDrie Well-Known Member Licensed User Longtime User Feb 9, 2025 #12 Welli a new speed requirement, perhaps it works to store the image in blob and the two otter parameters in a sqlite database, and store the database in the kvs to prevent conversion. Upvote 0
Welli a new speed requirement, perhaps it works to store the image in blob and the two otter parameters in a sqlite database, and store the database in the kvs to prevent conversion.
Sergey_New Well-Known Member Licensed User Longtime User Feb 9, 2025 #13 MicroDrie said: Welli a new speed requirement, perhaps it works to store the image in blob and the two otter parameters in a sqlite database, and store the database in the kvs to prevent conversion. Click to expand... Thank you, I'll keep that in mind. Upvote 0
MicroDrie said: Welli a new speed requirement, perhaps it works to store the image in blob and the two otter parameters in a sqlite database, and store the database in the kvs to prevent conversion. Click to expand... Thank you, I'll keep that in mind.