I’m very new to Java which is required for a Blackberry App development project (which is what I’m doing now). My issue is that I am trying to use this class I found online (attached below) to implement a notification feature in my application. As I said I’m extremely new to Java so I don’t know how to call the setVisible1 from another class, say UserInterface. I have tried MyAppIndicator._indicator.setVisible1(true,1); but this produces an error of:
“The method setVisible1(boolean, int) is undefined for the type ApplicationIndicator”.
Any help would be appreciated. Thanks!
public class MyAppIndicator
{
public ApplicationIndicator _indicator;
public static MyAppIndicator _instance;
private MyAppIndicator () {}
public static MyAppIndicator getInstance() {
if (_instance == null) {
_instance = new MyAppIndicator ();
}
return(_instance);
}
public void setupIndicator() {
//Setup notification
if (_indicator == null) {
ApplicationIndicatorRegistry reg = ApplicationIndicatorRegistry.getInstance();
_indicator = reg.getApplicationIndicator();
if(_indicator == null) {
ApplicationIcon icon = new ApplicationIcon(EncodedImage.getEncodedImageResource ("status_icon_24x24.png"));
_indicator = reg.register(icon, false, true);
_indicator.setValue(0);
_indicator.setVisible(false);
}
}
}
public void setVisible1 (boolean visible, int count) {
if (_indicator != null) {
if (visible) {
_indicator.setVisible(true);
_indicator.setValue(count);
} else {
_indicator.setVisible(false);
}
}
}
}
In order to call methods from Classes in Java, you need instance of the class (or if the class is ‘static’ you can directly use the methods, as ‘static’ basically means only 1 instance).
In your case
MyAppIndicatorimplements Singleton:This means that when you call getInstance() it will return instance of
MyAppIndicatorif such an instance already exists, or it will create a new one, if there’s no instance.
After acquiring an instance of a class, you simply call it’s methods, if they have the appropriate access modifiers. In your case
setVisible1has access modifier ‘public’ so you will be able to call it outside ofMyAppIndicator.So in code:
a) acquiring instance:
b) calling the method: