Having trouble with an else statement.........

I am having trouble figuring out what to do with this else statement error.........I can't seem to see where I am going wrong...............can anyone help? I can compile it but I just keep getting this one error I can't fix.....................
Program Name:     Transfer
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class Transfer extends Frame implements ActionListener
DataOutputStream output;
//Construct components
Panel dataFields = new Panel();
Panel firstRow = new Panel();
Panel secondRow = new Panel();
Panel thirdRow = new Panel();
Panel fourthRow = new Panel();
Panel buttonArea = new Panel();
Button submit = new Button("Submit");
Button exit = new Button("Exit");
Label firstNameLabel = new Label("Name:");
TextField firstName = new TextField(15);
Label studentIdLabel = new Label("Student ID:");
TextField studentId = new TextField(15);
Label transferCourseLabel = new Label("Transfer Course Number:");
TextField transferCourse = new TextField (15);
Label localCourseLabel = new Label("Local Course Number:");
TextField localCourses = new TextField (15);
public static void main(String args[])
Transfer window = new Transfer();
window.setTitle("Transfer Course Substitutions");
window.setSize(450, 250);
window.setVisible(true);
public Transfer()
//set backgound and layout managers
setBackground(Color.magenta);
setLayout(new BorderLayout());
dataFields.setLayout(new GridLayout(4,2));
FlowLayout rowSetup = new FlowLayout(FlowLayout.LEFT,4,2);
firstRow.setLayout(rowSetup);
secondRow.setLayout(rowSetup);
thirdRow.setLayout(rowSetup);
fourthRow.setLayout(rowSetup);
buttonArea.setLayout(new FlowLayout());
//Add fields to rows
firstRow.add(firstNameLabel);
secondRow.add(studentIdLabel);
thirdRow.add(transferCourseLabel);
fourthRow.add(localCourseLabel);
//Add rows to panel
dataFields.add(firstRow);
dataFields.add(secondRow);
dataFields.add(thirdRow);
dataFields.add(fourthRow);
//Add buttons to panel
buttonArea.add(submit);
buttonArea.add(exit);
//Add panels to frame
add(dataFields, BorderLayout.NORTH);
add(buttonArea, BorderLayout.SOUTH);
//Add functionality to buttons
submit.addActionListener(this);
exit.addActionListener(this);
// output states
try
output = new DataOuputStream(new FileOUtputStream("Transfer.dat"));
catch(IOException ex)
System.exit(1);
//construct window listener
addWindowListener(
new WindowAdapter()
public void windowClosing(WindowEvent e)
System.exit(0);
public void actionPerformed(ActionEvent e)
String arg = e.getActionCommand();
if (arg == "Submit")
try
output.writeUTF(code);
output.writeUTF(firstName.getText());
output.writeUTF(studentId.getText());
output.writeUTF(transferCourse.getText());
output.writeUTF(localCourse.getText());
catch(IOException ex)
System.exit(1);
clearFields();
else //code to execute if the user clicks Exit
try
output.close();
catch(IOException c)
System.exit(1);
System.exit(0);
public void clearFields()
firstName.setText("");
studentId.setText("");
transferCourse.setText("");
localCourse.setText("");
firstName.requestFocus();

The == method does work but it compares Object references and not the String contents. If the string you are comparing is actually the same object it will reply with 'true' also id both Strings are generated with quotes in the same methos and they contain the same string it will also work. This because the compiler will optimize your creating 2 identical Strings to 1 crete statement.
String a = "Hello";
String b = "Hello";
String c = new String("Hello");
String d = "He" + "llo";
String e = "He";
e +="llo";
a == b ==> true : because of optimization
a == c ==> false: because of different objects
a.equals(c) ==> true
a == d ==> true : because of optimization
a == e ==> false : because of different objects

Similar Messages

  • Having Trouble with nested Case Statements

    Hi Folks,
    I'm having trouble getting my head round nested case statements. For the life of me I cannot see what I'm missing here (unless my approach is all wrong).
    Any help much appreciated.
    Script:
    set serveroutput on format wrapped
    set feedback off
    set linesize 150
    DECLARE
    /* Set supported version here */
    ora_version VARCHAR2(4);
    unsupp_version EXCEPTION;
    /* Archive Log Info */
    db_log_mode VARCHAR2(12);
    BEGIN
    SELECT SUBSTR(VERSION, 1, 4)
    INTO ora_version
    FROM v$instance;
    SELECT log_mode
    INTO db_log_mode
    FROM v$database;
    CASE
    WHEN ora_version = '10.2' THEN
    DECLARE
    TYPE t_db IS RECORD(
    dflsh VARCHAR2(3),
    dcscn NUMBER);
    v_db t_db;
    BEGIN
    CASE
    WHEN db_log_mode = 'ARCHIVELOG' THEN
    EXECUTE IMMEDIATE 'SELECT INITCAP(flashback_on), current_scn FROM v$database'
    INTO v_db;
    DBMS_OUTPUT.PUT_LINE(' Flashback On : ' || v_db.dflsh);
    DBMS_OUTPUT.PUT_LINE(' Current SCN : ' || v_db.dcscn);
    DBMS_OUTPUT.PUT_LINE(' Log Mode : ' || db_log_mode);
    DBMS_OUTPUT.PUT_LINE(' Version : ' || ora_version);
    END;
    ELSE
    DBMS_OUTPUT.PUT_LINE(' Log Mode : ' || db_log_mode);
    DBMS_OUTPUT.PUT_LINE(' Version : ' || ora_version);
    END CASE;
    END;
    WHEN ora_version = '9.2' THEN
    DECLARE
    TYPE t_db IS RECORD(
    dcscn NUMBER);
    v_db t_db;
    BEGIN
    CASE
    WHEN db_log_mode = 'ARCHIVELOG' THEN
    EXECUTE IMMEDIATE 'SELECT current_scn FROM v$database'
    INTO v_db;
    DBMS_OUTPUT.PUT_LINE(' Current SCN : ' || v_db.dcscn);
    DBMS_OUTPUT.PUT_LINE(' Log Mode : ' || db_log_mode);
    DBMS_OUTPUT.PUT_LINE(' Version : ' || ora_version);
    END;
    ELSE
    DBMS_OUTPUT.PUT_LINE(' Log Mode : ' || db_log_mode);
    DBMS_OUTPUT.PUT_LINE(' Version : ' || ora_version);
    END CASE;
    END;
    ELSE
    RAISE unsupp_version;
    END CASE;
    EXCEPTION
    WHEN unsupp_version THEN
    DBMS_OUTPUT.PUT_LINE('');
    DBMS_OUTPUT.PUT_LINE(' Unsupported Version '||ora_version||' !');
    DBMS_OUTPUT.PUT_LINE('');
    END;
    set linesize 80
    set feedback on
    set serveroutput off
    Gives errors:
    END;
    ERROR at line 31:
    ORA-06550: line 31, column 7:
    PLS-00103: Encountered the symbol ";" when expecting one of the following:
    case
    ORA-06550: line 37, column 1:
    PLS-00103: Encountered the symbol "WHEN"
    ORA-06550: line 50, column 28:
    PLS-00103: Encountered the symbol ";" when expecting one of the following:
    case
    Edited by: milkyjoe on 28-Apr-2010 05:38

    Hi,
    Never write, much less post, unformatted code.
    Indent the code to show the extent of multi-line structures like BEGIN and CASE.
    For example:
    DECLARE
         /* Set supported version here */
         ora_version       VARCHAR2 (4);
         unsupp_version       EXCEPTION;
         /* Archive Log Info */
         db_log_mode      VARCHAR2 (12);
    BEGIN
         SELECT     SUBSTR(VERSION, 1, 4)
         INTO     ora_version
         FROM     v$instance;
         SELECT     log_mode
         INTO     db_log_mode
         FROM     v$database;
         CASE
             WHEN  ora_version = '10.2' THEN
              DECLARE
                  TYPE t_db IS RECORD(
                             dflsh     VARCHAR2(3),
                             dcscn      NUMBER);
                  v_db t_db;
              BEGIN
                  CASE
                      WHEN db_log_mode = 'ARCHIVELOG' THEN
                       EXECUTE IMMEDIATE 'SELECT INITCAP(flashback_on), current_scn FROM v$database'
                                           INTO v_db;
                       DBMS_OUTPUT.PUT_LINE(' Flashback On : ' || v_db.dflsh);
                       DBMS_OUTPUT.PUT_LINE(' Current SCN : ' || v_db.dcscn);
                       DBMS_OUTPUT.PUT_LINE(' Log Mode : ' || db_log_mode);
                       DBMS_OUTPUT.PUT_LINE(' Version : ' || ora_version);
                  END;
    ...The code above is what you posted, with some whitespace added.
    The error is much clearer; the last CASE statement concludes with END, but CASE blocks always have to conclude with END CASE .
    Why are you using a nested BEGIN block in the code above? Are you plannning to add an EXCEPTION handler later?
    When posting formatted text on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Having trouble with if else when used with event.value... please help

    Please can someone shed any light on where i'm going wrong.
    I have a pdf form that uses a drop down menu for the SubBrand and a series of checkboxes for the Location.
    the following code is placed as a custom calculation script in an address text field and what im after is dynamically setting the address based on the subbrand and location.
    However whats happening is the address only changes based on the location and not the subbrand.
    Does anyone please have any advice on this.
    Thanks
    if 
    ((this.getField("SubBrand").value == "Passion" || "Passion for Men") && (this.getField("Location").value == "WW")) {
    event.value = "Not Applicable";
    else if ((this.getField("SubBrand").value == "Passion" || "Passion for Men") && (this.getField("Location").value == "US")) {
    event.value = "US02";
    else if ((this.getField("SubBrand").value == "Passion" || "Passion for Men") && (this.getField("Location").value == "WH")) {
    event.value = "WH02";
    else if ((this.getField("SubBrand").value == "Adventure" || "Liquid" || "Silver") && (this.getField("Location").value == "WW")) {
    event.value = "WW01";
    else if ((this.getField("SubBrand").value == "Adventure" || "Liquid" || "Silver") && (this.getField("Location").value == "US")) {
    event.value = "US01";
    else if ((this.getField("SubBrand").value == "Adventure" || "Liquid" || "Silver") && (this.getField("Location").value == "WH")) {
    event.value = "WH01";
    else
    event.value = "";

    Thanks for the tip GIlad I've amended my code but am still experiencing the issue, im at a loss as to what is preventing the address field from changing when the subbrand changes.
    Can you suggest anything else that may be preventing this from happening?
    Updated Code:
    var subBrand = this.getField("SubBrand").value
    var location = this.getField("Location").value
    if      ((subBrand == "Passion" || "Passion for Men") && (location == "WW")) {
            event.value = "Not Applicable";
    else if ((subBrand == "Passion" || "Passion for Men") && (location == "US")) {
            event.value = "US02";
    else if ((subBrand == "Passion" || "Passion for Men") && (location == "WH")) {
            event.value = "WH02";
    else if ((subBrand == "Adventure" || "Liquid" || "Silver") && (location == "WW")) {
            event.value = "WW01";
    else if ((subBrand == "Adventure" || "Liquid" || "Silver") && (location == "US")) {
            event.value = "US01";
    else if ((subBrand == "Adventure" || "Liquid" || "Silver") && (location == "WH")) {
            event.value = "WH01";
    else    event.value = "";

  • I am having trouble with app updates on my iOS 5 iPhone never getting beyond the "waiting" state.

    I am having trouble with app updates on my iOS 5 iPhone never getting beyond the "waiting" state. I have tried signing out/in of my account, rebooting and removing/re-installing the apps.  This started shortly after going to iOS 5 but I am not certain if that is related.  All updates that I try now are stuck in "waiting".  I also tried removing the apps and then installing via iTunes desktop sync with no improvement.  The only thing that I have not tried so far is a restore to a prior iPhone backup.  I have not been able to find anything to indciate what the updates on waiting on.  There is plenty of space on the iPhone (16gb available).  Any suggestions on what to try next? 

    Hello there, Missy.
    First thing I would recommend is to check your downloads queue to make sure there is not an interrupted download per the following Knowledge Base article:
    iTunes: How to resume interrupted iTunes Store downloads
    http://support.apple.com/kb/HT1725
    If your download was interrupted using your iPhone, iPad, or iPod touch
    1. From the Home screen, tap the iTunes app.
    2. For iPhone or iPod touch, tap More > Downloads. For iPad, tap Downloads.
    3. Enter your account name and password if prompted.
    4. Tap the blue download arrow to resume.
    If you can't complete the download on your iOS device, you can download it in iTunes on your Mac or PC and then sync it to your iOS device. You can also transfer purchases from your iPhone, iPad, or iPod to a computer.
    For Apps, you can also try tapping on the application icon to resume the download, as outline in this featured discussion:
    App updates won't download on my...: Apple Support Communities
    https://discussions.apple.com/thread/4111336
    Try tapping the App, so that it changes to Paused instead of Waiting, then tap it again to resume the install.
    Make sure you don't have any paused downloads in other apps either, like the App Store or iTunes Store.
    If that doesn't do it, try resetting or restoring the iPhone.
    via whatheck
    Thanks for reaching out to Apple Support Communities.
    Cheers,
    Pedro.

  • Any one else having trouble with Creative Cloud not opening?

    Anyone else haveing trouble with Creative Cloud not opening? All I get is the splash screen and the :loading: symbol that keeps going around and around---forever.
    This just started ---.
    I am running Windows 8 on an i7 machine with 16 gigs of RAM. My internet connection is good---all other internet access opens just fine.
    Thanks
    gene

    Have you downloaded and installed the following updated Mountain Lion compatible driver and software for your model?:
        http://h10025.www1.hp.com/ewfrf/wc/softwareDownloadIndex?softwareitem=mp-107723- 1&cc=us&dlc=en&lc=en&os=219&product=4073738&sw_lang=
    Hope this helps

  • I have a Lucid 2 LG.  I have been having trouble with insuffient storage.  I have a 8G phone and have spent hours with Tier 2 tech trying to move info from the internal storage to the SD card with no luck,  When I go to storage in the settings it states t

    I have a Lucid 2 LG.  I have been having trouble with insuffient storage.  I have a 8G phone and have spent hours with Tier 2 tech trying to move info from the internal storage to the SD card with no luck,  When I go to storage in the settings it states that over 4 gigs is for Misc?  System data takes up over 4 gigs.  No one can tell me what system data consist of.  So My question is does anyone know what system data is?  I am assuming I have a 8 gigphone but can only use 4 gigs???

    System data is the OS or operating system.  That is where the recovery stays separated from the rest of the storage so that it doesn't get corrupted.  It is not accessible and non-movable.

  • Since installing the new OS i am having troubles with different appliction icons showing up on my main page twice (upper left corner), and not allowng me to select certain ones (app store specifically).   Anyone else having this issue?

    Help - anyone else out there having trouble with the new OS system on their ipad 2?    I am not getting mutliple copies of several apps ont he main page.  They are "collecting: in a pike int he upper left corner and the original application icon is no lobger working.    I have tried a hard sync, and that didn't help.

    It should only be able to have one copy of an app on the iPad. Have you tried a reset : press and hold both the sleep and home buttons for about 10 to 15 seconds (ignore the red slider), after which the Apple logo should appear - you won't lose any content, it's the iPad equivalent of a reboot.
    Do all the apps work ? In the past a few people have taken a screen shot of their iPad screen and that has then become their background picture - so some of the 'app's may actually be on your wallpaper picture and not actual apps. Have you tried changing the wallpaper to see if that makes any difference ?

  • Has anyone else been having trouble with the tom tom app?

    Has anyone else been having trouble with the tom tom app?

    Not me.
    Would you like to define a problem? You need to ask a better question .

  • Has anyone else been having trouble with safari ever since the update? I have restarted several times,mans it still doesn't work.

    Has anyone else been having trouble with safari ever since the update? I have restarted several times, it still doesn't work.

    Greetings Blueleoapple,
    After reading your post, it sounds like you are experiencing an error with Safari. You may want to consider resetting your device, which is different from restarting. This article provides detailed instructions for Restarting, and Reseting:
    Restart or reset your iPhone, iPad, or iPod touch - Apple Support
    How to restart
    Press and hold the Sleep/Wake button until the red slider appears.
    Drag the slider to turn your device completely off.
    After the device turns off, press and hold the Sleep/Wake button again until you see the Apple logo.
    How to reset
    You should reset your device as a last resort and only if you can't restart it.
    To reset, press and hold both the Sleep/Wake and Home buttons for at least 10 seconds, until you see the Apple logo.
    Thank you for contributing to Apple Support Communities.
    Best,
    Bobby_D

  • Anyone else having trouble with Hard Candy Cases?

    I ordered a Hard Candy Case back on 3/22. I subsequently received an e-mail from HCC stating that my case order was changed to the newer 'Kickstand' model. Fine. Just want my case. Now after 60 days of being on the market, I still don't have my case even though HCC debited my Paypal account on 3/22. I can't seem to get a response from them either.
    Anyone else having trouble with HardCandy? I hope I'm an isolated case (sorry!), but I am curious if there is a trend.
    Thanks,
    Chris

    After going away does it come back randomly too? if that is the case, maybe to do with trackpad sensing your gesture correctly?

  • Anyone else having trouble with missing ringtones after upgrading to 8.1.1

    Anyone else having trouble with missing ringtones after upgrading to 8.1.1?

    Try resetting the keyboard dictionary
    Settings>General>Reset>Reset Keyboard Dictionary

  • Anyone else having trouble with FCPX crashing after the OSX update?

    Anyone else having trouble with FCPX crashing after the OSX update? It NEVER crashed until the update. The night before last it crashed 20 times in 45 minutes. I can't finish my project because of it.
    Retina, Mid 2012
    Processor  2.3 GHz Intel Core i7
    Memory  8 GB 1600 MHz DDR3
    Graphics  NVIDIA GeForce GT 650M 1024 MB
    Software  OS X 10.9 (13A603)

    therealamaru wrote:
    I don't understand the question. I am simply editing.
    There are some patterns of crashes that suggest possible causes and fixes; some users report crashes when FCPX is in the process of loading; others while importing/exporting, etc. Asking to narrow the list of possibilities.
    Suggest starting with three things:
    1) Update the software from the APp Store  if need be.
    2) Trash preferences.
    3) Repair permissions.
    Russ

  • Anyone else having trouble with siri

    anyone else having trouble with siri today?

    i've seen a couple other posts with siri trouble!
    when you try to use her she said sorry please try again later or some variation to that.
    this happens sometimes.
    Siri is sick! lol I'm sure she'll be back later today, or by tomorrow for sure!

  • Anyone else having trouble with their iPad disconnecting from wifi since 6.0.1 update

    Anyone else having trouble with their iPad dropping wifi about once a week since 6.0.1 update?

    Some things to try first:
    1. Turn Off your iPad. Then turn Off (disconnect power cord for 30 seconds or longer) the wireless router & then back On. Now boot your iPad. Hopefully it will see the WiFi.
    2. Go to Settings>Wi-Fi and turn Off. Then while at Settings>Wi-Fi, turn back On and chose a Network.
    3. Change the channel on your wireless router (Auto or Channel 6 is best). Instructions at http://macintoshhowto.com/advanced/how-to-get-a-good-range-on-your-wireless-netw ork.html
    4. Go into your router security settings and change from WEP to WPA with AES.
    5.  Renew IP Address: (especially if you are droping internet connection)
        •    Launch Settings app
        •    Tap on Wi-Fi
        •    Tap on the blue arrow of the Wi-Fi network that you connect to from the list
        •    In the window that opens, tap on the Renew Lease button
    ~~~~~~~~~~~~~~~~~~~~~~~~~
    iOS 6 Wifi Problems/Fixes
    Fix For iOS 6 WiFi Problems?
    http://tabletcrunch.com/2012/09/27/fix-ios-6-wifi-problems/
    Did iOS 6 Screw Your Wi-Fi? Here’s How to Fix It
    http://gizmodo.com/5944761/does-ios-6-have-a-wi+fi-bug
    How To Fix Wi-Fi Connectivity Issue After Upgrading To iOS 6
    http://www.iphonehacks.com/2012/09/fix-wi-fi-connectivity-issue-after-upgrading- to-ios-6.html
    iOS 6 iPad 3 wi-fi "connection fix" for netgear router
    http://www.youtube.com/watch?v=XsWS4ha-dn0
    Apple's iOS 6 Wi-Fi problems
    http://www.zdnet.com/apples-ios-6-wi-fi-problems-linger-on-7000004799/
    ~~~~~~~~~~~~~~~~~~~~~~~
    Look at iOS Troubleshooting Wi-Fi networks and connections  http://support.apple.com/kb/TS1398
    iPad: Issues connecting to Wi-Fi networks  http://support.apple.com/kb/ts3304
    WiFi Connecting/Troubleshooting http://www.apple.com/support/ipad/wifi/
    How to Fix: My iPad Won't Connect to WiFi
    http://ipad.about.com/od/iPad_Troubleshooting/ss/How-To-Fix-My-Ipad-Wont-Connect -To-Wi-Fi.htm
    iOS: Connecting to the Internet http://support.apple.com/kb/HT1695
    iOS: Recommended settings for Wi-Fi routers and access points  http://support.apple.com/kb/HT4199
    How to Quickly Fix iPad 3 Wi-Fi Reception Problems
    http://osxdaily.com/2012/03/21/fix-new-ipad-3-wi-fi-reception-problems/
    iPad Wi-Fi Problems: Comprehensive List of Fixes
    http://appletoolbox.com/2010/04/ipad-wi-fi-problems-comprehensive-list-of-fixes/
    Fix iPad Wifi Connection and Signal Issues  http://www.youtube.com/watch?v=uwWtIG5jUxE
    Fix Slow WiFi Issue https://discussions.apple.com/thread/2398063?start=60&tstart=0
    How To Fix iPhone, iPad, iPod Touch Wi-Fi Connectivity Issue http://tinyurl.com/7nvxbmz
    Unable to Connect After iOS Update - saw this solution on another post.
    https://discussions.apple.com/thread/4010130
    Note - When troubleshooting wifi connection problems, don't hold your iPad by hand. There have been a few reports that holding the iPad by hand, seems to attenuate the wifi signal.
    ~~~~~~~~~~~~~~~
    If any of the above solutions work, please post back what solved your problem. It will help others with the same problem.
     Cheers, Tom

  • Anyone else having trouble with Itunes store? My account says I have entered the wrong security code for my credit card

    Anyone else having trouble with Itunes store? My account says I have entered the wrong security code for my credit card

    Yes, it happens to me all the time. I deleted an app because it froze the. Tried to redownloading it but it wouldn't let me ivd tried all of my cards and nothing works. I thought it was because I had a negative balance but I have a to of money all accounts. It'd be very helpful if someone could help us out.

Maybe you are looking for

  • Embedding cam feed in web page

    There have been a number of postings on this topic but here is a new thread. Users (me included) have noted that it is possible to embed a feed as shown here: http://fentyler.pwp.blueyonder.co.uk/mike-cam.htm This technique does however require Windo

  • Safari on ipad not logging onto website

    When attemting to logon to a secure site (such as my webmail account) Safari seems to hang or not pass full details through to the authenticating server and returns an error message (unable to log you on etc).  Any ideas - is there a setting on Safar

  • Photo limit

    Is there a limit on number of photo's ATV2 can handle?  It does not display my whole library, probably shows 20k of my 60k photos.

  • Mac osx 10.8.1 high fan

    I upgraded to the latest version of OSX Mountain lion yesterday (10.8.1) and my battery is only lasting 90 minutes and the fans are constantly on with hardly anything running, just a web browser. The fans are constantly on and the computer is rather

  • Flex application does not run in Internet Explorer(IE) browser

    The IE browser has the required version of the Flash player installed as a Active X control. Looked at the remoting-config.xml and services-config.xml files, but did not find anything which might prevents the application from running on IE. The appli