Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Contributor
erad888
Posts: 3
Registered: ‎07-21-2010
My Device: Not Specified

Changing User Interface Field

I am trying to integrate the GPS Demo Java program into my own independent program by calling the GPSDemo class from my program. I tried using: 

this.add(new GPSDemo());

but all i get is an error saying that the class is "multiply defined"

 

Is there some easy way I could modify the UserInterface class to include a GPS or some other type of field? Or is there some other way of integrating the GPS program?

 

Please Help.

 

Thanks in Advance.

Please use plain text.
Developer
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Changing User Interface Field

Welcome to the forums!

 

There are three basic ways to use the sample programs:

  1. Study how they accomplish what they do and then write your own code from scratch based on what you learned;
  2. Copy useful pieces of the sample code into your own project.
  3. Start with a copy of the sample code as an entire project and then turn it into the app that you want by adding, modifying, and deleting pieces.

I gather that you were trying to do something like #2, but with the entire sample app. That doesn't work because one UiApplication subclass can't be added to another one. Among the pieces that can be copied fairly easily are screens, fields, menu items, and non-UI methods of interacting with the device. If you aren't too far along with your app, though, you might consider option 3.




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Please use plain text.
New Contributor
erad888
Posts: 3
Registered: ‎07-21-2010
My Device: Not Specified

Re: Changing User Interface Field

[ Edited ]

Thanks for the advice :smileyhappy: but I couldn't seem to get your suggestions to work. I still got too many errors, probably because I'm not too sure what I'm doing.

I decided to make an easy program to access the GPSDemo but even though I am literally copying the same UserInterface sample program code(which runs perfectly fine), I am getting different errors.

 

With the following code, I am getting a "Warning!: method 'odometer.Odometer.main(String[])' not invoked." indicated at "Odometer theApp = new Odometer();"

Why doesn't java invoke the public static main?

 

 

public class Odometer extends UiApplication {
    
    public static void main(String[] args) {
        Odometer theApp = new Odometer();
        theApp.enterEventDispatcher();
    }
    public Odometer() {
        pushScreen(new OdometerScreen());
    }
}
final class OdometerScreen extends MainScreen {
    
    public OdometerScreen() {
        super();
        
        LabelField title = new LabelField("User Interface edit:Albert",LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
        setTitle(title);
        
        new GPSDemo().enterEventDispatcher();
        //pushScreen(new GPSDemo());
    }
    
    public boolean onClose() {
            Dialog.alert("Goodbye!");
            System.exit(0);
            return true;
        }
    
    
}

 

 

Please Help! Thanks in Advance

 - Aggrivated Student

Please use plain text.
Developer
Ted_Hopp
Posts: 1,305
Registered: ‎01-21-2009
My Device: Not Specified

Re: Changing User Interface Field

I'm not sure why you're getting the warning. Are you using Eclipse?

 

Be aware that the call to enterEventDispatcher never returns. So by calling GPSDemo().enterEventDispatcher() in the c'tor for OdometerScreen, that's the end of your code's execution. I'd be curious to know if the warning goes away if you comment out that line.

 

What exactly are you trying to do?




Solved? click "Accept as solution". Helpful? give kudos by clicking on the star.
Please use plain text.