Thread: Need help urgent with error!!

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    5

    Need help urgent with error!!

    I got this code (a snippet):

    Code:
        class PrintMenu
    
        {
    
            public int Hoofdmenu()
    
            {
    
                try{
    
                    Console.Clear();
    
                    int Keuze = 0;
    
                    Console.WriteLine("**** Welkom bij het DBA project van Vandersteegen Jan ****");
    
                    Console.WriteLine("----------------------------------------------------------\n\n");
    
                    Console.WriteLine("Kies wat u wilt doen: \n");
    
                    Console.WriteLine("  |***********************************************************************|");
    
                    Console.WriteLine("  | 1: Inlezen van CSV bestand met nieuwe gebruikers om aan te maken.     |");
    
                    Console.WriteLine("  | 2: Exporteren van bestaande gebruikers naar een CSV bestand           |");
    
                    Console.WriteLine("  | 3: Verwijderen van bestaande gebruikers op basis van een CSV bestand  |");
    
                    Console.WriteLine("  | 4: Afsluiten van het programma                                        |");
    
                    Console.WriteLine("  |***********************************************************************| \n\n");
    
                    Console.Write("U keuze: ");
    
                    Keuze = int.Parse(Console.ReadLine());
    
    				
    
                    return Keuze;
    
               }
    
                catch (Exception ex)
    
               {
          ......
    at the part where it says: Keuze = int.Parse(Console.ReadLine());
    I get an error. It looks like it keeps skipping the readline part and just tries to convert nothing to a integer.
    I tried making a seperate string variable for my input and then converting it to an int but that just gives me the same error... just like its skipping the readline like I said, and doesn't wait for my input :s

    Any help would be very appreciated.

    to be exact it's this error:
    System.ArgumentNullException: Argument cannot be null.
    Parameter name: s
    at System.Int32.Parse (System.String s) [0x00000]
    at VandersteegenJan_DBAProject_2010.PrintMenu.Hoofdme nu () [0x0006b] in /home/jean/Desktop/VandersteegenJan-DBAProject-2010/VandersteegenJan-DBAProject-2010/Program.cs:138
    this all works in windows visual studio but not in monodeveloper 2.2 on linux
    Last edited by Tiglet; 03-14-2010 at 02:46 PM.

  2. #2
    (?<!re)tired Mario F.'s Avatar
    Join Date
    May 2006
    Location
    Ireland
    Posts
    8,446
    Hmm... tricky. The code you show is essentially correct, although malformed in my opinion.

    Anyways, as the runtime error implies, Int32.Parse() string argument cannot be null. Console.ReadLine() will return null if no lines can be read. But the only way for this to actually happen is for someone to terminate entering text with CTRL+Z, instead of ENTER.

    My guess is Mono is not respecting this and a null reference is being returned when the input string is empty (instead of an empty string as it should).
    Originally Posted by brewbuck:
    Reimplementing a large system in another language to get a 25% performance boost is nonsense. It would be cheaper to just get a computer which is 25% faster.

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    if it is Mono - and you are using monoDevelop - in the project settings for Run choose "Use External Console" - this fixed for me the Readline issue
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    Registered User
    Join Date
    Feb 2010
    Posts
    5
    I'm running monodevelop 2.2 and it doesn't seem to have that option vart? Any help on that?

    Thanks already guys!

  5. #5
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by Tiglet View Post
    I'm running monodevelop 2.2 and it doesn't seem to have that option vart? Any help on that?

    Thanks already guys!
    my is 2.0

    what about compiling the executable and running it from terminal and not from the IDE?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  6. #6
    Registered User
    Join Date
    Feb 2010
    Posts
    5
    found it sorry, were so many options windows Thanks mate, it worked, very much appreciated!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  4. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM