BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 04-14-2005, 07:27 AM   #1
Nayade
New Member
 
Join Date: Apr 2005
Posts: 1
Question Adding menu items to BlackBerry applications

Please Login to Remove!

Hello and sorry for my english
I add an ApplicationMenuItem to a Blackberry Contacts application, but when I click in this menu item I have an error:
"application already running in this process"

This the code of the Blackberry example:

Code:
package com.rim.samples.docs.menuitem;
import net.rim.device.api.system.*;
import net.rim.device.api.ui.component.Dialog.*;
import net.rim.blackberry.api.menuitem.*;
import javax.microedition.pim.*;
import com.rim.samples.docs.contactsdemo.*;


public final class DemoAppMenuItem extends Application {
    private static long ID = 0x7cab1e23b72a0033L; 
    //com.rim.samples.docs.menuitem
    
    public static void main(String[] args) {
        DemoAppMenuItem app = new DemoAppMenuItem();
        app.enterEventDispatcher();
    }
    
    DemoAppMenuItem() {
        ApplicationMenuItemRepository amir = 
        ApplicationMenuItemRepository.getInstance();
        amir.addMenuItem(ApplicationMenuItemRepository.MENUITEM_ADDRESSCARD_VIEW,
        new SampleMenuItem());
    }
   
    private static class SampleMenuItem extends ApplicationMenuItem {
        SampleMenuItem() {
            super(20);
        }
        
        public String toString() {
            return "Open the Contacts Demo";
        }
        
        public Object run(Object context) {
            Contact c = (Contact)context; //an error if this doesn't work
            if ( c != null ) {
                new ContactsDemo().enterEventDispatcher();
            } else { 
                throw new IllegalStateException( "Context is null, expected a Contact instance");
            }
            net.rim.device.api.ui.component.Dialog.alert("Viewing an email message in the email view");
            return null;
        }
    }
}
And the ContactsDemo is a library project and the class extends UiApplication

Thanks a lot!

Last edited by Nayade; 04-14-2005 at 10:18 AM..
Offline  
Old 04-15-2005, 06:56 AM   #2
arconsulting
Thumbs Must Hurt
 
Join Date: Aug 2004
Location: Metro NYC
Posts: 175
Default

In your run() method, don't instantiate a new ContactsDemo() app. Instantiate it in your main() and just call whatever methods you need in run().
__________________
-- Aric Rosenbaum
BlackBerry consulting, BlackBerry development
www.arconsultinginc.com
BlackBerry consulting and development (RIM SI Partner)
Offline  
Closed Thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


Vintage Apple Computer 4” Paper Cube Notepad Macintosh 80s 90s Office White picture

Vintage Apple Computer 4” Paper Cube Notepad Macintosh 80s 90s Office White

$39.95



6502 CPU - Over 100 chips on a vintage 4 inch Silicon wafer picture

6502 CPU - Over 100 chips on a vintage 4 inch Silicon wafer

$275.00



Apple 1 Replica IC's: Vintage IC’s Many Types See List NOS 74XXX Types - Apple I picture

Apple 1 Replica IC's: Vintage IC’s Many Types See List NOS 74XXX Types - Apple I

$20.00



Vintage Post-it Note Pad Apple Magnetic Holder Pince A Notes Unused 1988 NOS picture

Vintage Post-it Note Pad Apple Magnetic Holder Pince A Notes Unused 1988 NOS

$16.99



Lot of 6 Vintage Apple Drawstring Bags For iPhone, Mac, Apple Watch, iPod picture

Lot of 6 Vintage Apple Drawstring Bags For iPhone, Mac, Apple Watch, iPod

$45.00



Retro 1951 Apple Computer Logo 0.7mm Ballpoint Black Ink Pen Gold Barrel picture

Retro 1951 Apple Computer Logo 0.7mm Ballpoint Black Ink Pen Gold Barrel

$56.41







Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.