Edit: While writing the post I messed up the thread title. It should read "How can I cast a B4A-Map to java.util.map?"
However, Erel helped to to find a solution (#6)to the real problem.
----- ----- ----- ----- -----
(I am trying to solve the problem of picture #2 from this, so I hope it's not a "duplicate" post)
While working with this library I get an error "Map cannot be cast to java.util.map"
Since I have no JAVA experience I was thinking that maybe a B4A-Map is different from a JAVA-Map.
While trying to make a cast function with Inline-JAVA I was not able to get it running because I don't know how to set the parameters etc.
What I need is someting like this:
to use the function in B4A like:
However, Erel helped to to find a solution (#6)to the real problem.
----- ----- ----- ----- -----
(I am trying to solve the problem of picture #2 from this, so I hope it's not a "duplicate" post)
While working with this library I get an error "Map cannot be cast to java.util.map"
#-btnSend_Click
#-submitPost, strTitle=Testtitle, strBody=Testmessage
testfibart_writenewpost (java line: 791)
java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.Map cannot be cast to java.util.Map
at de.donmanfred.DatabaseReferenceWrapper.updateChildren(DatabaseReferenceWrapper.java:222)
at b4a.example.fibadb2.testfibart._writenewpost(testfibart.java:791)
at b4a.example.fibadb2.testfibart._submitpost(testfibart.java:732)
at b4a.example.fibadb2.testfibart._btnsend_click(testfibart.java:440)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:5204)
at android.view.View$PerformClick.run(View.java:21155)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5422)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
#-submitPost, strTitle=Testtitle, strBody=Testmessage
testfibart_writenewpost (java line: 791)
java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.Map cannot be cast to java.util.Map
at de.donmanfred.DatabaseReferenceWrapper.updateChildren(DatabaseReferenceWrapper.java:222)
at b4a.example.fibadb2.testfibart._writenewpost(testfibart.java:791)
at b4a.example.fibadb2.testfibart._submitpost(testfibart.java:732)
at b4a.example.fibadb2.testfibart._btnsend_click(testfibart.java:440)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:169)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:157)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:153)
at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:78)
at android.view.View.performClick(View.java:5204)
at android.view.View$PerformClick.run(View.java:21155)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5422)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
While trying to make a cast function with Inline-JAVA I was not able to get it running because I don't know how to set the parameters etc.
What I need is someting like this:
B4X:
#If JAVA
public static castb4amaptojavamap(object mapB4A ) {
import anywheresoftware.b4a.objects.collections.Map;
Map m = new Map();
m.Initialize();
m = mapB4A;
return m.getObject();
}
#End If
to use the function in B4A like:
B4X:
Dim childUpdates as Map
childUpdates.Initialize
childUpdates.Put("Key1", "testvalue1")
Private nativeMe As JavaObject
nativeMe.InitializeStatic(Application.PackageName & ".testfibart")
mDatabase.updateChildren( nativeMe.RunMethod("castb4amaptojavamap", childUpdates) )
Last edited: