Java Question using Inner classes

alwaysbusy

Expert
Licensed User
Longtime User
Hi,

I'm having a error I can't seem to figure out with a library class I'm trying to write. It's a class containing a class. I want to return this inner class object to b4a so i can access its properties and functions (something like agraham does in the Encryption library).

The inner class is visible in b4a but when it compiles i get the following error on the dim b command:

B4X:
Compiling code.                         0.00
Generating R file.                      0.00
Compiling generated Java code.          Error
B4A line: 15
Dim b As SubtTest
javac 1.6.0_21
src\com\AB\TestMultiObjTest\main.java:168: an enclosing instance that contains com.AB.TestMultiObj.TestMultiObj.SubTest is required
_b = new com.AB.TestMultiObj.TestMultiObj.SubTest();
     ^
1 error

the java is this:

B4X:
package com.AB.TestMultiObj;

import anywheresoftware.b4a.BA.Author;
import anywheresoftware.b4a.BA.ShortName;
import anywheresoftware.b4a.BA.Version;

@ShortName("TestMultiObj")
@Version(1.0f)
@Author("Alain Bailleul")
public class TestMultiObj {
   private SubTest mySubTest=null;
   
   public void Start() {
      mySubTest=new SubTest();
      mySubTest.subveld = "Alain";
   }
   
   public SubTest ReturnSubTest() {
      return mySubTest;
   }
   
   @ShortName("SubtTest")
   public class SubTest {
      public String subveld="";
   }
}

The b4a code is this:

B4X:
'Activity module
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.
   
End Sub

Sub Globals
   'These global variables will be redeclared each time the activity is created.
   'These variables can only be accessed from this module.
   Dim a As TestMultiObj
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Dim b As SubtTest ' <--- [B]the error happens here[/B]
   a.Start
   b = a.ReturnSubTest()
   Msgbox (b.subveld, "")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

I'm sure it's something stupid i'm doing, but i can figure out what :)

Thanks in advance for the help!
 
Top