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 6 of 6

Thread: Runtime error? Case issues? it seems to remember commands?

  1. #1
    Junior Member
    Join Date
    Jan 2019
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Runtime error? Case issues? it seems to remember commands?

    Hi so I'm doing a simple assignment but I'm really a newbe so please don't be too harsh. To the issue, in my schools compiling programme it says something like it cannot execute the commands, command failed

    So the error message
    Ange ditt val här:
    [IN:register new dog]
    Detta är inte ett giltigt val // the error code is shown for some reason after the enter your choice
    Välkommen till mitt hunddagis

    [1] register new dog
    [2] list dogs
    [3] increase age
    [4] remove dog
    [5] exit

    Ange ditt val här:
    [IN:exit]
    Detta är inte ett giltigt val
    Välkommen till mitt hunddagis // repeating

    [1] register new dog
    [2] list dogs
    [3] increase age
    [4] remove dog
    [5] exit

    Ange ditt val här:
    [TEST TIMED OUT WHILE: waiting for program to close. Most likely this is caused by a previous error, so start by looking for one above.] // so I just feel retarded right now, me and a few people have looked at this without being able to sort it out.

    The code
    import java.util.Scanner;
    import java.util.ArrayList;
     
    public class ProgHundDagis {
     
    private static Scanner myscan;
     
        	public static void main(String[] args) {
        	ArrayList<Hund> doglist = new ArrayList<Hund>();
        	myscan = new Scanner(System.in);
        	boolean running = true;
        	while (running) {
        		System.out.println("Välkommen till mitt hunddagis");
        		System.out.println("\n[1] register new dog");
        		System.out.println("[2] list dogs");
        		System.out.println("[3] increase age");
        		System.out.println("[4] remove dog");
        		System.out.println("[5] exit");
        		System.out.println("\nAnge ditt val här: ");
        		String option = myscan.nextLine();
            		switch (option) {
        		case "1": 
        			System.out.println("register new dog");
        			System.out.println("Name:");
        			String name = myscan.nextLine();
        			System.out.println("Race:");
        			String race = myscan.nextLine();
        			System.out.println("Age:");
        			int age = myscan.nextInt();// myscan.nextLine();
        			System.out.println("Weight:");
        			double weight = myscan.nextDouble();// myscan.nextLine();
        			doglist.add(new Hund(name, race, age, weight));
        			break;
        		case "2":
        			System.out.println("list dogs");
        			break;
        		case "3":
        			System.out.println("increase age");
        			break;
        		case "4":
        			System.out.println("remove dog");
        			break;
        		case "5":
        			System.out.println("exit");
        			myscan.close();
        			running = false;
        			break;
     
        		default:
        			System.out.println("Detta är inte ett giltigt val");
        		}
        	}
        }
    }
    Last edited by Jeanieus; January 18th, 2019 at 06:56 AM.

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Runtime error? Case issues? it seems to remember commands?

    it says something like it cannot execute the commands
    That doesn't give much of a clue.
    Is the error found while compiling the code
    or during the code's execution?

    Can you use the javac command to compile the code
    and if there are no compiler errors use the java command to execute the generated class file?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Jan 2019
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Runtime error? Case issues? it seems to remember commands?

    Quote Originally Posted by Norm View Post
    That doesn't give much of a clue.
    Is the error found while compiling the code
    or during the code's execution?

    Can you use the javac command to compile the code
    and if there are no compiler errors use the java command to execute the generated class file?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    Ah sorry, i'll see if I can edit the format in the entry.
    But basically what I get is

    [TEST TIMED OUT WHILE: waiting for program to close. Most likely this is caused by a previous error, so start by looking for one above.]

    And that after I fullfill case 1 I can continue the program but it will also give my error.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Runtime error? Case issues? it seems to remember commands?

    TEST TIMED OUT
    Is that because the user did not enter data for the program to read and process?
    Can you copy the full contents of the console from when you execute the program and paste it here?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    Jan 2019
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Runtime error? Case issues? it seems to remember commands?

    Quote Originally Posted by Norm View Post
    Is that because the user did not enter data for the program to read and process?
    Can you copy the full contents of the console from when you execute the program and paste it here?
    So like all we get is that we upload the file and that the programme is evaluating it and that it gets stuck and gives me this message

    Ange ditt val här:
    [IN:register new dog]
    Detta är inte ett giltigt val // the error code is shown for some reason after the prompt to enter your choice
    Välkommen till mitt hunddagis

    [1] register new dog
    [2] list dogs
    [3] increase age
    [4] remove dog
    [5] exit

    Ange ditt val här:
    [IN:exit]
    Detta är inte ett giltigt val
    Välkommen till mitt hunddagis // repeating

    [1] register new dog
    [2] list dogs
    [3] increase age
    [4] remove dog
    [5] exit

    Ange ditt val här:
    [TEST TIMED OUT WHILE: waiting for program to close. Most likely this is caused by a previous error, so start by looking for one above.] // so I just feel retarded right now, me and a few people have looked at this without being able to sort it out.
    I tried recreating the issue but the program still runs but it shows the error text after it shows the options if you've registered a new dog.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Runtime error? Case issues? it seems to remember commands?

    The error message should include the bad value:
       System.out.println("Detta är inte ett giltigt val option="+option + "<");
    The print out will show you what the value was that the program did not recognize.

    Did you write all of the code that was posted or was some code written by someone else?
    This message should say that a value from 1 to 5 is expected, not some text:
      System.out.println("\nAnge ditt val här: ");
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Why runtime error?
    By hooshdar3 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: March 16th, 2014, 01:40 PM
  2. Runtime error-- Applet program
    By amar5445 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 28th, 2013, 07:32 AM
  3. Runtime Error
    By Dennis Enya in forum What's Wrong With My Code?
    Replies: 1
    Last Post: July 24th, 2013, 12:44 PM
  4. Error with case 51031:
    By Sh0ck in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 24th, 2013, 09:58 AM
  5. Runtime Error
    By SyntheticD in forum What's Wrong With My Code?
    Replies: 5
    Last Post: February 10th, 2011, 04:09 PM