Java Question How To Initialize B4A Map in Java

52manhua

Member
Licensed User
Longtime User
I take it for granted, but it doesn't seem to work.

B4X:
package com.example;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.*;
import anywheresoftware.b4a.objects.collections.Map;

@Version(1.0f)
//@Permissions(values={"android.permission.INTERNET"})
@ShortName("FirstLib")
//@DependsOn(values={"some java library "})
//@ActivityObject
public class FirstLib {
    //b4a map
    anywheresoftware.b4a.objects.collections.Map mlunar = new anywheresoftware.b4a.objects.collections.Map();
    mlunar.Initialize();

When compiling, the Initialize() is wrong.
So, what's right? Thx
 

52manhua

Member
Licensed User
Longtime User
Where is the error message?
err.png


Well, in English it's Maybe:

B4X:
Error: < Missing identifier >
Mlunar.Initialize ();
^
1 mistakes

Perhaps, I should paste full code here:

B4X:
package com.example;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.*;
import anywheresoftware.b4a.objects.collections.Map;

@Version(1.0f)
//@Permissions(values={"android.permission.INTERNET"})
@ShortName("FirstLib")
//@DependsOn(values={"some java library "})
//@ActivityObject
public class FirstLib {
    //b4a map
    anywheresoftware.b4a.objects.collections.Map mlunar = new anywheresoftware.b4a.objects.collections.Map();
    mlunar.Initialize();

    private final static String[] LUNAR_MONTH_ARRAYS = {"\u6b63", "\u4e8c", "\u4e09", "\u56db", "\u4e94", "\u516d", "\u4e03", "\u516b", "\u4e5d", "\u5341", "\u51ac", "\u814a"};
    private final static String[] LUNAR_DAY_ARRAYS = {"\u521d", "\u5341", "\u5eff", "\u5345"};
    private final static String[] NUMBERS = {"\u4e00", "\u4e8c", "\u4e09", "\u56db", "\u4e94", "\u516d", "\u4e03", "\u516b", "\u4e5d", "\u5341"};

    public int add(int x, int y) {
        return x + y;
    }

    public String test()
    {
        return LUNAR_MONTH_ARRAYS[0];
    }
   
    public anywheresoftware.b4a.objects.collections.Map test2(){
        mlunar.getObject().put("a",1);
        mlunar.getObject().put("b",3);
        return mlunar;
    }
}
 
Top