Jump to content
Awoo.

FormatException Error


baba_944

Recommended Posts

So I'm fairly new to programming and I've been following this gentleman's video tutorial for a good while and is very helpful and informative. The other day, I've been watching him teaching us Exception handling in C# and he told us to type this:

 

StreamReader SR = new StreamReader("C:\\Test\\Sonic.txt");

Console.WriteLine(SR.ReadToEnd());

SR.Close();

 

It ran fine for me and that's why I've dived deeper into his tutorials. Until yesterday, when I decided instead of watching more of his tutorials I'd practice code for awhile. Then that's when the problem arises. I typed it in exactly as he had it, I even double checked it, but then it gave me a FormatException Error. It ran smoothly, but then the command prompt window gave me that error. This block of code should execute what's in the text file and put that in the command prompt window. I've researched "what causes FormatException errors", "ways you can get FormatException errors", and things of that nature but to no avail.

 

Thanks for the help.

 
Link to comment
Share on other sites

  • Replies 6
  • Created
  • Last Reply

Top Posters In This Topic

  • Tails spin

    3

  • baba_944

    3

  • goku262002

    1

Popular Days

Top Posters In This Topic

I haven't used C# before but I have used C++ and Java. Currently I'm taking a more advanced Java course to brush up my skill in a specific programming language.

 

From what I have seen in java may or may not apply to C# but in java you have to import a specific class in order to read in files or input from the user.

 

in the input case we need a Scanner library to read in input.

 

that may have been the case.

Link to comment
Share on other sites

Also it would help if you provided all the code. just a piece of it won't help much. does the error message specifically point to that portion of the code

Link to comment
Share on other sites

I gotcha:

 

using System;

using System.IO;

 

namespace Practice2

{

 

class MainClass

 

{

   

    public static void Maid()

{

 

     StreamReader SR = new StreamReader("C:\\Test\\Sonic.txt");

     Console.WriteLine(SR.ReadToEnd());

     SR.Close();

 

}

 

}

 

}

 

}

   

That's all. I'm in Monodevelop.

Link to comment
Share on other sites

So if this is your copied code then look at the public static void Maid().

 

its a small spelling error

 

its public static void Main()

 

try that first if not let me know cuz everything else seems to be fine.

 

edit:

I think you also have an extra }.

Link to comment
Share on other sites

While unrelated I don't think you guys know theres a special tag for coding:

While its not in the Special BBCode settings you can still use it by putting [code*] [*/code] tags sans *
just make sure to only use the tag once otherwise the 1st code tag wipes the others out.
Link to comment
Share on other sites

So if this is your copied code then look at the public static void Maid().

 

its a small spelling error

 

its public static void Main()

 

try that first if not let me know cuz everything else seems to be fine.

 

edit:

I think you also have an extra }.

That wasn't' the compiler's mistake those two mistakes were mine. This was not copy/paste I typed it by hand. Here's the real code:

 

using System;

using System.IO;

namespace Practice2

{

    class MainClass

    {

        public static void Main ()

        {

            StreamReader SR = new StreamReader("C:\\Test\\G.txt");

            Console.WriteLine(SR.ReadToEnd());

            SR.Close();

        }

    }

}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

You must read and accept our Terms of Use and Privacy Policy to continue using this website. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.