Java Question How To Initialize B4A Map in Java

Discussion in 'Libraries developers questions' started by 52manhua, Sep 4, 2018.

Tags:
  1. 52manhua

    52manhua Member Licensed User

    I take it for granted, but it doesn't seem to work.

    Code:
    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
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Where is the error message?
     
  3. 52manhua

    52manhua Member Licensed User

    err.png

    Well, in English it's Maybe:

    Code:
    Error: < Missing identifier >
    Mlunar.Initialize ();
    ^
    1 mistakes
    Perhaps, I should paste full code here:

    Code:
    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;
        }
    }
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    The Java code is invalid. The code must be inside a method. I recommend you to use Eclipse to write the Java code.
     
  5. 52manhua

    52manhua Member Licensed User

    I'll try,
    Thank you all the time.
     
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