B4J Question How to fix SLC "error: BA is abstract; cannot be instantiated"

MicroDrie

Well-Known Member
Licensed User
I have installed the 64 bit version 9.40 of B4J. Because I also want to create the JavaDoc with SLC version 1.11, I use javac 1.8.0_361. That doesn't cause any problems, except for the code below:

Declare and initialize a B4J variable in Java:
package b4x.example;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BA.*;

@Version(1.0f)
//@Permissions(values={"android.permission.INTERNET"})
@ShortName("B4JTest")
//@DependsOn(values={"some java library "})
//@ActivityObject
public class B4JTest {
    
/**
  * How to declare and initialize a B4J variable in Java
  */
    public static void changeB4JVariable(String[] args) {
        // Get a reference to the current B4J instance
        BA ba = new BA(null, null);

        // Read a B4J variable
        int _myvariable = (int) ba.sharedProcessBA.getBBObject().getField("_myvariable");

        // Write a B4J variable
        ba.sharedProcessBA.getBBObject().setField("_myvariable", _myvariable + 1);
    }
}

The above Java routine with SLC gives the following error:
SLC error:
Starting step: Compiling Java code.
javac 1.8.0_361
D:\Data\1 B4X SLC\SimpleLibraryCompiler\SimpleLibraryCompiler\A B4JTest\src\b4x\example\B4JTest.java:18: error: BA is abstract; cannot be instantiated
        BA ba = new BA(null, null);
                ^
1 error


Error.

What am I doing wrong and how do I fix this error message?
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

MicroDrie

Well-Known Member
Licensed User
Why are you doing this???
I have tried several found examples, they all give errors.
I changed the code to your suggestion:
Second try:
/**
  * How to declare and initialize a B4J variable in Java
  */
    public static void changeB4JVariable(BA ba, String[] args)
    {
        // Read a B4J variable
        int _myvariable = (int) ba.sharedProcessBA.getBBObject().getField("_myvariable");

        // Write a B4J variable
        ba.sharedProcessBA.getBBObject().setField("_myvariable", _myvariable + 1);
    }

Which give me this error code:
Second try error code:
Starting step: Compiling Java code.
javac 1.8.0_361
D:\Data\1 B4X SLC\SimpleLibraryCompiler\SimpleLibraryCompiler\A B4JTest\src\b4x\example\B4JTest.java:22: error: cannot find symbol
        int _myvariable = (int) ba.sharedProcessBA.getBBObject().getField("_myvariable");
                                  ^
  symbol:   variable sharedProcessBA
  location: variable ba of type BA
1 error


Error
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
BA class in B4J, unlike B4A, does not have a sharedProcessBA field, Also it is declared abstract in B4J, again unlike B4A, so you can't instantiate it without sub-classing it - not that you would normally ever need to.

The getBBObject() method puzzled me. I can't see it existing in either B4A or B4J BA classes. If you are wanting to access the Process_Global variables of an instance of a class module then they are declared as public static fields of the class.
 
Upvote 0
Top