Won't evaluate my if statement as true even though it is?

import java.io.*;
import java.util.Scanner;
public class Main {
    private static final String DATAFILE = "Ass3.dat";
    private static final String INDEXFILE = "Ass3.idx";
    private static final int NAMELENGTH = 20;
    private static final int ADDRESSLENGTH = 100;
    private static final int PHONELENGTH = 15;
    private static final int RECORDLENGTH = NAMELENGTH + ADDRESSLENGTH + PHONELENGTH;
    public static void main (String[] args) {
        Table table = new HashTable();
        Scanner scan = new Scanner(System.in);
        byte buffer[] = new byte[RECORDLENGTH];
        String selection = "-1";
        String name = null;
        String address = null;
        String phNumber = null;
        try {
            RandomAccessFile dataFile = new RandomAccessFile(DATAFILE, "rw");
            File indexFile = new File(INDEXFILE);
            long nextRecord = dataFile.length();
            long recordNumber = nextRecord/RECORDLENGTH;
            if (indexFile.createNewFile()) {
                //if no index file exists
                System.out.println("There is no existing file. A file has been created.");
                do {
                    System.out.println("");
                    System.out.println("Please select from the following options and input a number for your selection:");
                    System.out.println("[1] Create a new address book by loading a text file");
                    System.out.println("[2] Create a new address book by inputing records manually");
                    System.out.println("");
                    System.out.print("What is your selection? ");
                    selection = scan.next();
                    if ((!selection.equals("1")) && (!selection.equals("2"))) {
                        System.out.println("This is not a valid selection. Please try again.");
                } while ((!selection.equals("1")) && (!selection.equals("2")));
            else { //the index file was found
                ObjectInputStream is = new ObjectInputStream(new FileInputStream(indexFile));
                table = (Table) is.readObject();
                is.close();
                System.out.println("An existing file has been found and loaded.");
            do {
                if (selection == "1") {
                    System.out.println("This option is not yet available.");
                    selection = "$";
                else if (selection == "2") {
                    while (selection != "$") {
                ..etc I didn't post the whole thing because it's huge. I'm using bluej and i put a breakpoint in, when it gets to the if (selection == "1") satement, the debugger tells me it's got the value "1" but it skipps over the if statement that should be true :S
Any suggestions?

G.W. wrote:
Just a small tip:
it's always safe to do this:
"1".equals(variable);and it's not always safe to do this:
variable.equals("1");where of course variable was previously declared as String. First comparison will never throw an exception second one may cause NullPointerException when variable == null. So in order to avoid checking wheather or not you can actually invoke equals() on a variable it's beter to invoke equals on literal.
Regards,Although having said that, it's not automatically a good idea to avoid NPEs. If the value should never be null, you have a bug, and you're as well to find it there, rather than somewhere further down the line

Similar Messages

  • I currently have my credit card on my iTunes account and when I have no money in my bank account it won't let me download the free apps even though they don't cost anything. How do I stop this so I can download or remove my credit card?

    I currently have my credit card on my iTunes account and when I have no money in my bank account it won't let me download the free apps even though they don't cost anything. How do I stop this so I can download or remove my credit card?

    All downloads from iTunes are tied to the account that downloaded it, you can't re-download content via a different account. You checked the spam folder on yourr old account as well as the Inbox, and depending upon how long ago you did it, have you retried getting it reset : http://appleid.apple.com, then 'reset your password' ?

  • How can i delete an app on my desktop that says it won't delete because it's still open, even though i have done force quit numerous times.

    How can i delete an app on my desktop that says it won't delete because it's still open, even though i have done force quit numerous times? I even deleted it's files in my Finder and it just won't go away.  Help please!! TIA

    Restart the computer then delete it.
    Uninstalling Software: The Basics
    Most OS X applications are completely self-contained "packages" that can be uninstalled by simply dragging the application to the Trash.  Applications may create preference files that are stored in the /Home/Library/Preferences/ folder.  Although they do nothing once you delete the associated application, they do take up some disk space.  If you want you can look for them in the above location and delete them, too.
    Some applications may install an uninstaller program that can be used to remove the application.  In some cases the uninstaller may be part of the application's installer, and is invoked by clicking on a Customize button that will appear during the install process.
    Some applications may install components in the /Home/Library/Applications Support/ folder.  You can also check there to see if the application has created a folder.  You can also delete the folder that's in the Applications Support folder.  Again, they don't do anything but take up disk space once the application is trashed.
    Some applications may install a startupitem or a Log In item.  Startupitems are usually installed in the /Library/StartupItems/ folder and less often in the /Home/Library/StartupItems/ folder.  Log In Items are set in the Accounts preferences.  Open System Preferences, click on the Accounts icon, then click on the LogIn Items tab.  Locate the item in the list for the application you want to remove and click on the "-" button to delete it from the list.
    Some software use startup daemons or agents that are a new feature of the OS.  Look for them in /Library/LaunchAgents/ and /Library/LaunchDaemons/ or in /Home/Library/LaunchAgents/.
    If an application installs any other files the best way to track them down is to do a Finder search using the application name or the developer name as the search term.  Unfortunately Spotlight will not look in certain folders by default.  You can modify Spotlight's behavior or use a third-party search utility, EasyFind, instead.
    Some applications install a receipt in the /Library/Receipts/ folder.  Usually with the same name as the program or the developer.  The item generally has a ".pkg" extension.  Be sure you also delete this item as some programs use it to determine if it's already installed.
    There are many utilities that can uninstall applications.  Here is a selection:
        1. AppZapper 2.0.1
        2. AppDelete 3.2.6
        3. Automaton 1.50
        4. Hazel
        5. AppCleaner 2.1.0
        6. CleanApp
        7. iTrash 1.8.2
        8. Amnesia
        9. Uninstaller 1.15.1
      10. Spring Cleaning 11.0.1
    For more information visit The XLab FAQs and read the FAQ on removing software.

  • I have an Ipad and an Ipod Touch 5th gen both on the latest firmwares but they won't connect via bluetooth whenever I try even though both shows that the devices are discoverable. I need help!

    I have an Ipad and an Ipod Touch 5th gen both on the latest firmwares but they won't connect via Bluetooth whenever I try even though both shows that the devices are discoverable. I also tried connecting them with my Bluetooth enabled laptop but it also didn't worked. Because of the Bluetooth not working I also can't enable airdrop.

    What model iPad?
    What model computer and OS version>
    AirDrop requires:
    What you need
    To share content with AirDrop, both people need one of these devices using iOS 7 or later, or a Mac with OS X Yosemite:
    iPhone 5 or later
    iPad (4th generation or later)
    iPad mini
    iPod touch (5th generation)
    You also need to turn on Wi-Fi and Bluetooth. If you want to share with your contacts, sign in to your iCloud account.
    Learn more about using AirDrop to share with people using a Mac with Yosemite.
    Use AirDrop to wirelessly share content - Apple Support
    System Requirements
    To see if your Mac works with AirDrop, make sure you’re in the Finder by clicking the desktop (the background area of your screen), or by clicking the Finder icon in the Dock. Then, check to see if AirDrop is listed as an option in the Go menu. If you don't see AirDrop listed, your Mac doesn't support this feature.
    In order to transfer files between a Mac and and an iPhone, iPad or iPod touch
    your iOS device needs to include a lightning connector
    your iOS device needs iOS 7 or later installed
    your Mac needs to be a 2012 or later model with OS X Yosemite installed
    Your Mac and iOS device both need bluetooth and Wi-Fi turned on. You do not have to be connected to a specific Wi-Fi network.
    To transfer files between two Mac computers, you need the Mac models listed below with Wi-Fi turned on and OS X Lion or later installed.
    MacBook Pro (Late 2008 or newer)*
    MacBook Air (Late 2010 or newer)
    MacBook (Late 2008 or newer)*
    iMac (Early 2009 or newer)
    Mac Mini (Mid 2010 or newer)
    Mac Pro (Early 2009 with AirPort Extreme card, or Mid 2010)
    *The MacBook Pro (17-Inch Late 2008) and the white MacBook (Late 2008) do not support AirDrop.
    For help identifying your Mac, choose About This Mac from the Apple menu. You can refer to the Apple Support website to find out if your iPhone, iPad or iPod Touch includes a lightning connector.
    Mac Basics: AirDrop lets you send files from your Mac to nearby Macs and iOS devices - Apple Support
    Otherwise you need an app to pair via BT one iOS device to another iOS device. There may be apps that allow pairing with a Mac computer. The iOS devioces do not have the BT profiles necessary natively to pair with a computer or another iOS device except for AirDrop

  • IPod Classic won't turn on unless plugged into wall even though battery is charged

    I plugged in my old iPod Classic and charged it up for a long time. I got that little plug symbol that indicates that it's fully charged. The iPod turns on and works fine when it's plugged into the wall, but as soon as I unplug it, it won't do anything at all. Just black screen. I also tried plugging it into the computer. Nothing.
    I tried re-setting by toggling the "Hold" button and then pressing Play/Pause and Menu at the same time. Nothing.
    Why would it be fine when plugged into the wall but not when unplugged or plugged into the computer? Is it possible that is really is not fully charged even though it did show that little plug symbol? It had been just sitting for many months.

    Hi there,
    How old is your Classic? Often, after a couple of years, rechargable batteries begin to fail, especially after such a long period of inactivity. This happens with any gadget with this type of battery.
    Try leaving it plugged in for 24 hours, and try again, to rule out that it isn't just really low on charge. If this doesn't help, it may be a good time to buy a replacement. New iPod Nanos and Touches will be released this October.
    Below, I've linked to an Apple website which explains rechargable batteries, and why yours may not be working.
    Apple - Batteries
    I hope this helps, and I hope upgrading your device will not feel like an unnecessary expense. Let me know if you have any more questions,
    Nathan

  • Won't warn me when closing multiple tabs - even though it is selected in preferences.

    When I close Firefox, it used to give me the option of saving my tabs. It doesn't do that anymore, even though I have that option selected under Preferences.

    You can set the warn prefs on the about:config page to true via the right-click context menu or toggle with a double left-click.
    * browser.showQuitWarning, see http://blog.zpao.com/post/3174360617/about-that-quit-dialog
    * browser.tabs.warnOnClose, see http://kb.mozillazine.org/About%3Aconfig_entries
    * browser.warnOnQuit , see http://kb.mozillazine.org/browser.warnOnQuit
    * browser.warnOnRestart , see http://kb.mozillazine.org/browser.warnOnRestart
    To open the <i>about:config</i> page, type <b>about:config</b> in the location (address) bar and press the "<i>Enter</i>" key, just like you type the url of a website to open a website.<br />
    If you see a warning then you can confirm that you want to access that page.<br />
    You can use History > Restore Previous Session to get back the previous session.<br />
    There is also a "Restore Previous Session" button on the default about:home Home page.
    Another possibility is to use:
    *[http://kb.mozillazine.org/Menu_differences Firefox > Preferences] > General > Startup: "When Firefox Starts": "Show my windows and tabs from last time"

  • My phone is telling me there is a billing problem with a precious purchase and won't let me download or update anything even though the apps in trying to download are free and updates are free. And I only have one card so I can't update my payment info

    My phone is telling me that I have a billing problem with a precious purchase but I only have one card so I can't update my payment information so I can't update anything or download anything. What should I do?

    Are you aware of any problem with a previous purchase ? If not then you should contact iTunes Support and see if they can tell you what it is (until it's sorted you won't be able to download anything from the store) : http://www.apple.com/support/itunes/contact/- click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption
    If you go into the payment details section on your account then does it say anything about your card being declined or not accepter or if the security code needs re-entering ?

  • Won't let me sign in on iTunes even though I'm doing it right

    Itunes has been working succefully for 2 days, but today i tried to purchase a song and it said that my password was wrong but it wasnt my sn was correct there wasnt cap locks on and it was on AOL account and it won't let me go on forgot password it just says "URL couldn't be open" so what is it? what should i do?

    Try  here:
    The Complete Guide to FaceTime: Set-up, Use, and Troubleshooting Problems

  • It won't let me make an inapp purchase even though I have the funds available

    Just like the title says. I try to make an in-app purchase. It denies me, saying it's unable to connect to the iTunes Store. Then it gives me a contact apple.com/support/iTunes/ww/.

    If you haven't already done so then you can contact iTunes Support via this link and ask them why the message is appearing (we are fellow users here on these forums, we won't know why) : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • I'm locked out my MacBook and its only typing in symbols it even turned my wifi off and I can't re install Mavericks because it won't let me connect to my wifi even though I have wifi please help!!

    II'm locked out my MacBook and its only typing symbols and now I can't re install Mavericks becwise I'm locked out and the numbers won't work to connect to my work when I type nothing ail pop up but symbols instead of letters

    Does the iPod connect to other networks?
    Does the iPod see the network?
    Any error messages?
    Do other devices now connect?
    Did the iPod connect before?
    Try the following to rule out a software problem:                 
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Power off and then back on the router
    - Reset network settings: Settings>General>Reset>Reset Network Settings
    - iOS: Troubleshooting Wi-Fi networks and connections
    - Wi-Fi: Unable to connect to an 802.11n Wi-Fi network
    - iOS: Recommended settings for Wi-Fi routers and access points
    - Try changing the security on the router. Start with no securty as a test.
    - Restore from backup. See:
    iOS: How to back up
    - Restore to factory settings/new iOS device.
    If still problem make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
    Apple Retail Store - Genius Bar

  • My iPhone 4S won't change orientation from portrait to landscape even though its portrait orientation is unlocked? I got it two days ago and it has always been this way? Do I need to get a new one or can I fix it?

    So it is new (two days old I got it on the 20th of June) and the orientation of the screen will not change from portrait. I have looked at the lock in the multitasking bar and unlocked it and still nothing changes. YouTube, photos, texts, nothing works. Siri has also been blacking out while I use her so do I need a replacement for this defective phone? I got it from RadioShack Thursday. On a totally unrelated note does using your phone while charging it damage the battery? Anyway thanks

    Try this
    Restart iPhone: Hold down the Sleep/Wake button and the home button together until the apple logo appears (ignore the ON/OFF slider) then let both buttons go and wait for phone to restart (no data will be lost).
    Using the phone while charging doesn't create a problem.. I do it all the time

  • Why won't my itunes connect with my music even though its authorized?

    I tried to unsync my Ipod but when I did it it said that I have a total of 39 errors because My computer wasn't Authorized. But I went to go authorize my computer and it said ok now your computer is authorized out of 5, but what came up before still came up again. How do I solve this problem??? Please get back to me on this. Thanks!

    Maybe:
    iTunes repeatedly prompts to authorize computer to play iTunes Store purchases

  • How do I remove a film that won't download because of shortage of space even though l pay £2.99 per month for extra  200gb.I tried removing most of my apps and my photos basically I removed everything on this iPad and I am still frigging stuck with t

    How do I get rid of a movie downloaded that was bought from iTunes .I hired Amistad but had insuffient  to downloaded  so I bought extra GB @ £2.99 a month .I got rid of my apps on the hope I could delete it but the same again insuffient  storage.So after doing all this trying to get rid of this movie

    Buying extra iCloud storage has given you extra space for your backups, it doesn't give you extra space on your iPad for downloading content. Your current free space on your iPad is shown in Settings > General > About > Available - the film's size should be shown on its description page in the store (HD films can be over 5 gig).
    If you want to stop it downloading then does it show in the Downloads tab in the iTunes store app - if it does then does swiping/dragging across it from right-to-left give you a Delete button on it ? And/or does it show in Settings > General  Usage > Videos, and if it does can you delete it from there ?
    You could also try the 'report a problem' page to contact iTunes Support and see if they will refund you for the rental, or grant you a re-download so that can download it on your computer's iTunes instead : http://reportaproblem.apple.com
    If the 'report a problem' link doesn't work then you can try contacting iTunes Support via this page : http://www.apple.com/support/itunes/contact/ - click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • Firefox won't open my Dreamweaver files to preview even though I have it designated as one of my browsers in Dreamweaver...help!

    Within Dreamweaver, you can specify which browser you would like to preview your files in. I have Firefox as one of my designated browsers, as well as Safari, Opera, etc. So, when I go to preview an edited file, they will not open for preview in Firefox. They will open in all my other browsers...
    The best I can get is the default browser window, with no edited website file in it...just default window. Should open right up in the browser...

    There is a fix for Dreamweaver, so it works in Firefox 3.6+ versions:
    http://solutions.marketingmedley.com/
    There is a $5.00 fee for that Dreamweaver fix. That website and the fix are not associated with Mozilla in any manner. Support for that fix is provided by that that website via email.

  • My ios 7 update won't go past the Terms and Conditions even though I press accpet...what do I do?

    I need help!!

    Try a Reset...
    Reset  ( No Data will be Lost )
    Press and hold the Sleep/Wake button and the Home button at the same time for at least ten seconds, until the Apple logo appears. Release the Buttons.
    http://support.apple.com/kb/ht1430

Maybe you are looking for

  • I can't cut and paste

    I want to cut and paste on my web page but the functions are not available and grayed out. I modified the user_pref as directed substituting the web page url for modzilla.org (actually cut and pasted exactly using notepad with no success. The modific

  • Cant sync my ipod shuffle 4th gen to itunes

    Hi - I got this shuffle as a gift.  After installation, I am unable to connect to the itunes and hence unable to sync the songs.  Ran the diagnostics but still getting the following error: Microsoft Windows 7 x64 Home Basic Edition Service Pack 1 (Bu

  • Roaming between WLANs on different WLCs

    Hello, Is it possible to create the same SSIDs on two different WLCs that are not in a failover or mobility group but have an interface on the same network so that users can connect to those SSIDs automatically without having to do it manually?  For

  • Mac authentication by IAS in WAP4410N

    I have a access point model WAP4410N , I want to configure for mac authentication by using MS IAS , but when I set MY SSID to radius in wireless connection control and try to connect to that SSID by a labtop I didn't get any logs in my IAS , anybody

  • PSE 11 downloads from the adobe site give 'archive missing' error

    I downloaded the two files three times after deleting each time.  Everytime I run the exe file, I get the error message.  Is the file corrupt or can I download from somewhere else.  I need to repair a screwed up PSE 11 installation.   Yes they are in