Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

How to call module method in js code

$
0
0

I have a module class:

@Kroll.module(name="TestHelpers", id="com.home.testhelpers")
public class TestHelpersModule extends KrollModule
{
 
    // Standard Debugging variables
    private static final String LCAT = "TestHelpersModule";
    private static final boolean DBG = TiConfig.LOGD;
 
    // You can define constants with @Kroll.constant, for example:
    // @Kroll.constant public static final String EXTERNAL_NAME = value;
 
    public TestHelpersModule()
    {
        super();
    }
 
    @Kroll.onAppCreate
    public static void onAppCreate(TiApplication app)
    {
        Log.d(LCAT, "inside onAppCreate");
        // put module init code that needs to run when the application is created
    }
 
    // Properties
    @Kroll.getProperty
    public int getNumber()
    {
        return 0;
    }
 
}
I've built it and loaded into my project just as the guide tells. Now, in my index.js file I do this:
$.index.open();
 
var module = require("com.home.testhelpers");
 
alert(module.getNumber());
When running this code, I'm getting: Uncaught TypeError: Object #<TestHelpers> has no method 'getNumber'. So what should I do to call this code?

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>