BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 08-11-2008, 01:34 PM   #1 (permalink)
Knows Where the Search Button Is
 
Join Date: Apr 2007
Model: 8900
OS: 4.6.1.94
PIN: N/A
Carrier: Swisscom / Orange CH
Posts: 29
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default My if statement went wrong / java beginner

Please Login to Remove!

Hello everbody,

I tried some stuff out used as basement the HelloWorld application. Because I am a beginner. What I tried to do it that you can enter your name hit "Check the Name!" and he should do if statements to give back messages. But something is going wrong I allways get the else never the if even if I am 100% sure that I typed it correct.

Code:
/**
 * HelloWorld.java
 * Copyright (C) 2001-2003 Research In Motion Limited. All rights reserved.
 */
package com.rim.samples.helloworld;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;

/*
 * BlackBerry applications that provide a user interface
 * must extend UiApplication.
 */
public class HelloWorld extends UiApplication
{
        public static void main(String[] args)
        {
                //create a new instance of the application
                //and start the application on the event thread
                HelloWorld theApp = new HelloWorld();
                theApp.enterEventDispatcher();
    }
        public HelloWorld()
        {
                //display a new screen
                pushScreen(new HelloWorldScreen());
        }
}

//create a new screen that extends MainScreen, which provides
//default standard behavior for BlackBerry applications
final class HelloWorldScreen extends MainScreen
{
    private EditField _edtField;
    private String name;
        public HelloWorldScreen()
        {

                //invoke the MainScreen constructor
                super();

                //add a title to the screen
                LabelField title = new LabelField("HelloWorld Sample", LabelField.ELLIPSIS
                                | LabelField.USE_ALL_WIDTH);
                setTitle(title);
                _edtField = new EditField();
                //add the text "Hello World!" to the screen
                add(new RichTextField("Ihr Name? / Your Name?"));
                add(_edtField);
        }

        //override the onClose() method to display a dialog box to the user
        //with "Goodbye!" when the application is closed
        public boolean onClose()
        {
            Dialog.alert("Bye!Bye!");
            System.exit(0);
            return true;
        }
        
        private MenuItem _closeItem = new MenuItem("Close", 200000, 10) {
                public void run()
                {
                        onClose();
                }
        };
        
        private MenuItem _viewItem = new MenuItem("Check the Name!", 110, 10) {
                public void run() {

                        //store the selected city in a variable
                        name = _edtField.getText();

                        //display a new screen with information about the
                        //selected city
                        if (name == "test")
                        {
                            Dialog.alert("test was entered");
                        }
                        else if (name == "blabla")
                        {
                            Dialog.alert("blabla was entered");
                        }
                        else
                        {
                            Dialog.alert("!"+name+"!");
                        }
                }
        };
        
        //Menü erstellen
        protected void makeMenu( Menu menu, int instance )
        {
                menu.add(_viewItem);
                menu.add(_closeItem);
        }
}
Thanks for your help,
Yves
Offline  
Old 08-11-2008, 01:46 PM   #2 (permalink)
CrackBerry Addict
 
Join Date: May 2005
Location: Golden, CO US
Model: 9700
Carrier: ATT
Posts: 684
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

You can't test for (name == "something") in Java.
Try (name.equals("something"))
Offline  
Old 08-12-2008, 12:02 AM   #3 (permalink)
Knows Where the Search Button Is
 
Join Date: Apr 2007
Model: 8900
OS: 4.6.1.94
PIN: N/A
Carrier: Swisscom / Orange CH
Posts: 29
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot RemyJ worked out flawlessly!
Offline  
Closed Thread


Thread Tools

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





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