Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: infinite maze issue

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation infinite maze issue

    So I'm trying to make an infinite maze for my beginner Java class, where the while loop will keep the user stuck until the 'secret word' is entered.
    The only issue I am having is that it is procession with exit code 1.

    Not sure what to do. I will post my code and the output, hopefully to get some help. I've tried mixing up the operator in the while loop and nothing seems to work. Please help. Thank you.

    Code:


    import javax.swing.JOptionPane;

    public class infinite
    {
    public static void main(String[] args)
    {
    int number = 0;
    String north = "You're in an abandoned warehouse. Choose a new direction.";
    String south = "You're in a burning building! Choose a new direction.";
    String east = "You fell in a pit of snakes! Choose a new direction.";
    String west = "You're in a sticky, smelly swamp. Choose a new direction.";
    String escape = "escape";
    String choose = "Choose a direction: North, South, East or West.";
    String wrong = "Thats not a correct direction.";
    String input;

    input = JOptionPane.showInputDialog(choose);

    while (input != escape)
    {
    if (input.equalsIgnoreCase("north"))
    {
    JOptionPane.showInputDialog(north + choose);
    number++;
    }
    else if (input.equalsIgnoreCase("south"))
    {
    JOptionPane.showInputDialog(south + choose);
    number++;
    }
    else if (input.equalsIgnoreCase("east"))
    {
    JOptionPane.showInputDialog(east + choose);
    number++;
    }
    else if (input.equalsIgnoreCase("west"))
    {
    JOptionPane.showInputDialog(west + choose);
    number++;
    }
    else
    {
    JOptionPane.showInputDialog(wrong + choose);
    number++;
    }
    }

    JOptionPane.showMessageDialog(null, "Congratulations! You've escaped with the secret word!");
    JOptionPane.showMessageDialog(null, "It took you " + number + " tries to escape the maze.");

    System.exit(0);

    }
    }


    Output Error:

    /Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/bin/java -Didea.launcher.port=7533 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 12 CE.app/bin" -Dfile.encoding=UTF-8 -classpath "/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/lib/javafx-doclet.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/lib/tools.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre/lib/htmlconverter.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre/lib/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre/lib/JObjC.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.7.0_25.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Users/Mike/Desktop/CIS 1500/infiniteMaze/out/production/infiniteMaze:/Applications/IntelliJ IDEA 12 CE.app/lib/idea_rt.jar" com.intellij.rt.execution.application.AppMain Destination
    Exception in thread "main" java.lang.ClassNotFoundException: Destination
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:4 24)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 57)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:190)
    at com.intellij.rt.execution.application.AppMain.main (AppMain.java:113)

    Process finished with exit code 1

    again, Thank you in advanced for any help.


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: infinite maze issue

    Do not compare String objects using ==, !=, <=, <, >, . . . etc. Use the equals() method.

  3. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: infinite maze issue

    I have removed the operand and replaced it with a boolean flag to make it easier and i'm still getting the same error. Here is my updated code:


    import javax.swing.JOptionPane;

    public class infinite
    {
    public static void main(String[] args)
    {
    int number = 0;
    String north = "You're in an abandoned warehouse.";
    String south = "You're in a burning building!";
    String east = "You fell in a pit of snakes!";
    String west = "You're in a sticky, smelly swamp.";
    String choose = "Choose a direction: North, South, East or West.";
    String wrong = "Thats not a correct direction.";
    String input;
    boolean getout = false;

    while (getout == false)
    {
    input = JOptionPane.showInputDialog(choose);

    if (input.equalsIgnoreCase("escape"))
    {
    getout = true;
    number++;
    }
    else if (input.equalsIgnoreCase("north"))
    {
    JOptionPane.showMessageDialog(null, north);
    number++;
    }
    else if (input.equalsIgnoreCase("south"))
    {
    JOptionPane.showMessageDialog(null, south);
    number++;
    }
    else if (input.equalsIgnoreCase("east"))
    {
    JOptionPane.showMessageDialog(null, east);
    number++;
    }
    else if (input.equalsIgnoreCase("west"))
    {
    JOptionPane.showMessageDialog(null, west);
    number++;
    }
    else
    {
    JOptionPane.showMessageDialog(null, wrong);
    number++;
    }
    }

    JOptionPane.showMessageDialog(null, "Congratulations! You've escaped with the secret word!");
    JOptionPane.showMessageDialog(null, "It took you " + number + " tries to escape the maze.");

    System.exit(0);

    }
    }

  4. #4
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: infinite maze issue

    Post your code in code tags.

    Your program seems to work fine here. I suspect you're having a development environment, IDE, or IDE setup problem.

  5. #5
    Junior Member
    Join Date
    Sep 2013
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: infinite maze issue

    ok, i copy and pasted the code in a new project and it ran fine. Thanks again!

Similar Threads

  1. Why do I get an infinite loop?
    By Skynet928 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 22nd, 2013, 08:29 PM
  2. [SOLVED] Infinite while loop for myKybd
    By DANGEROUSSCION in forum Loops & Control Statements
    Replies: 6
    Last Post: December 13th, 2012, 06:45 AM
  3. Infinite Loop in my code.
    By Vinster271 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 16th, 2012, 03:46 AM
  4. Infinite loop?
    By jackfletcher in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 30th, 2012, 01:06 PM
  5. [SOLVED] Infinite loop issue
    By Sharmeen in forum Loops & Control Statements
    Replies: 1
    Last Post: October 20th, 2012, 12:18 PM