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


PD-9A Polarity Checker Phase Detector Self-Test Auto-Off Audio Speaker Testing picture

PD-9A Polarity Checker Phase Detector Self-Test Auto-Off Audio Speaker Testing

$45.00



Audio Polarity Checker Phase Detector Self-Test Auto-Off PD-9A Speaker Tester picture

Audio Polarity Checker Phase Detector Self-Test Auto-Off PD-9A Speaker Tester

$43.00



IndusTec DC 20A Motor Polarity Reversing - Toggle Switch Maintained DPDT 3 Pos picture

IndusTec DC 20A Motor Polarity Reversing - Toggle Switch Maintained DPDT 3 Pos

$14.99



IndusTec 20 AMP 12v DC Momentary Reverse Polarity Rocker Switch DPDT SEE VIDEO picture

IndusTec 20 AMP 12v DC Momentary Reverse Polarity Rocker Switch DPDT SEE VIDEO

$9.99



Honeywell Quartz Polarity Sensitive Hour Meter 85098 picture

Honeywell Quartz Polarity Sensitive Hour Meter 85098

$79.99



Allen Bradley 937ZH-DPBN-2 Intrinsic Safety Zener Barrier, Positive Polarity DC picture

Allen Bradley 937ZH-DPBN-2 Intrinsic Safety Zener Barrier, Positive Polarity DC

$139.99







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