Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6875617

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:21:12+00:00 2026-05-27T04:21:12+00:00

I’m working through the book Beginning BlackBerry 7 Development and really putting my little

  • 0

I’m working through the book Beginning BlackBerry 7 Development and really putting my little or non existent oop/java skills to the test- eclipse is throwing up an error from the code in the book stating that loginhandler hasn’t been declared- and yes its correct- it hasn’t been declared but it also hasn’t been declared in the book.

What has been done is an inner class called logincommandhandler (at the bottom of my code) which can be seen in an excerpt here- http://my.safaribooksonline.com/book/-/9781430230151/chapter-4-user-interface-basics/67 – this is what its meant to be calling (i assume) but my limited oop skills i do not know what loginHandler should be- should it be defined somewhere with a type?

(there is no erata for the book)

package com.beginningblackberry.uifun;

import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.HorizontalFieldManager;

import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.EditField;
import net.rim.device.api.ui.component.PasswordEditField;
import net.rim.device.api.ui.component.SeparatorField;
import net.rim.device.api.ui.component.LabelField;

import net.rim.device.api.ui.component.CheckboxField;
import net.rim.device.api.ui.component.ObjectChoiceField;
import net.rim.device.api.ui.component.ButtonField;
import net.rim.device.api.ui.FieldChangeListener;

import net.rim.device.api.ui.component.Menu;
import net.rim.device.api.ui.MenuItem;
import net.rim.device.api.util.StringProvider;

import net.rim.device.api.command.Command;
import net.rim.device.api.command.CommandHandler;
import net.rim.device.api.command.ReadOnlyCommandMetadata;

public class UiFunMainScreen extends MainScreen implements FieldChangeListener {

    BitmapField img;
    EditField usernameField;
    PasswordEditField passwordField;
    ObjectChoiceField domainField;
    CheckboxField rememberCheckBox;
    ButtonField clearButton, loginButton;

    public UiFunMainScreen(){
        Bitmap logoBitmap = Bitmap.getBitmapResource("img/upd8rLOGO.png");


        img = new BitmapField(logoBitmap, Field.FIELD_HCENTER);     
        add(img);
        add(new SeparatorField());
        add(new LabelField("Please Enter Your Credentials:"));



        usernameField = new EditField("Username:","");
        passwordField = new PasswordEditField("Password:","");
        domainField = new ObjectChoiceField("Domain",new String[] {"Home","Work"});
        rememberCheckBox = new CheckboxField("Remember password",false);
        add(usernameField);add(passwordField);
        add(domainField);
        add(rememberCheckBox);

        add(new SeparatorField());
        clearButton = new ButtonField("Clear",ButtonField.CONSUME_CLICK);
        loginButton = new ButtonField("Login",ButtonField.CONSUME_CLICK);

        HorizontalFieldManager buttonManager = new HorizontalFieldManager(Field.FIELD_RIGHT);
        buttonManager.add(clearButton);
        buttonManager.add(loginButton);

        add(buttonManager);

        clearButton.setChangeListener(this);
        //loginButton.setChangeListener(this);
        loginButton.setCommand(new Command(LoginHandler));


    }
    //routing
    public void fieldChanged(Field field, int context){

        if(field == clearButton){
            clearTextFields();
        }else if(field == loginButton){
            login();
        }
    }


    private void login(){
        if(usernameField.getTextLength()== 0 || passwordField.getTextLength() == 0){
            Dialog.alert("You must enter a username and password");
        }
        else
        {
            String username = usernameField.getText();
            String selectedDomain = (String) domainField.getChoice(domainField.getSelectedIndex());
            LoginSuccessScreen loginSuccessScreen = new LoginSuccessScreen(username, selectedDomain);
            UiApplication.getUiApplication().pushScreen(loginSuccessScreen);
        }

    }
    public void clearTextFields ()
    {
        usernameField.setText("");
        passwordField.setText("");

    }
    protected void makeMenu(Menu menu, int instance){
        super.makeMenu(menu, instance);
        /*
        menu.add(new MenuItem(new StringProvider("Login"),20,10){

            public void run(){
                login();
            }   
        });
        */

        //login menu item       
        MenuItem loginMenu = new MenuItem(new StringProvider("Login"),20,10);
        loginMenu.setCommand(new Command(LoginHandler));
        menu.add(loginMenu);


        //clear text menu item
        menu.add(new MenuItem(new StringProvider("Clear"),20,10){
            public void run(){
                clearTextFields();
            }   
        });
    }

    class LoginCommandHandler extends CommandHandler
    {

        public void execute(ReadOnlyCommandMetadata metadata, Object context){
            login();
        }
    }


}

and the error-

LoginHandler cannot be resolved to a variable   UiFunMainScreen.java    /UiFun/src/com/beginningblackberry/uifun    line 69 Java Problem

any blackberry/java wizards shed some light on where i am going wrong?

Update

No one really answered the question bang on- to call the new inner class i called this instead

MenuItem loginMenu = new MenuItem(new StringProvider("Login"),20,10);
loginMenu.setCommand(new Command(new LoginCommandHandler()));
menu.add(loginMenu);

update 2 second answer

Declaring loginHandler as a class variable also works –

LoginCommandHandler loginHandler = new LoginCommandHandler();
  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I am trying to loop through a bunch of documents I have to put
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.