Jump to content


Photo

Ch 4 Pool Puzzle - Issue With "main" Entry Point


  • Please log in to reply
4 replies to this topic

#1 Gildren

Gildren

    Active Member

  • Members
  • PipPip
  • 13 posts

Posted 27 March 2014 - 01:40 PM

To solve the pool puzzle, I created a program with a one-button form to make it work. The program says in part:

C5 Pool Puzzle P159.exe' has more than one entry point defined: 'WindowsFormsApplication1.Program.Main()'.  Compile with /main to specify the type that contains the entry point."

Which I suppose is correct, as it points me to the Program.cs file, which has
static void Main()
in there, and my class which has
public static void Main(string[] args)
. The problem is, I don't know how to resolve the conflict. What should I do?

#2 AndrewStellman

AndrewStellman

    Andrew Stellman

  • O'Reilly Author
  • PipPipPipPipPipPipPipPipPipPipPip
  • 811 posts
  • Gender:Male
  • Location:Brooklyn, NY
  • Interests:Author of: "Head First C#", "Beautiful Teams", "Head First PMP", "Applied Software Project Management"

Posted 29 March 2014 - 10:01 AM

You're using the second edition, right? Flip back to pages 52 through 54 -- the problem is that your program now has two entry points. On page 54 you renamed the Main() method in Program.cs, which removed the entry point and caused a compile error. (In the third edition, this discussion is on pages 92 through 94.)

Try renaming the Main() method in Program.cs, that will get rid of your error. But really, what you want is to create a console application, where the main class is called Triangle. You'll learn more about console applications later in the book.


Andrew Stellman
Author, Head First C#
Building Better Software -- http://www.stellman-greene.com

#3 Gildren

Gildren

    Active Member

  • Members
  • PipPip
  • 13 posts

Posted 10 April 2014 - 12:59 PM

You're using the second edition, right? Flip back to pages 52 through 54 -- the problem is that your program now has two entry points. On page 54 you renamed the Main() method in Program.cs, which removed the entry point and caused a compile error. (In the third edition, this discussion is on pages 92 through 94.)

Try renaming the Main() method in Program.cs, that will get rid of your error. But really, what you want is to create a console application, where the main class is called Triangle. You'll learn more about console applications later in the book.



That worked. Thank you!

#4 Gildren

Gildren

    Active Member

  • Members
  • PipPip
  • 13 posts

Posted 10 April 2014 - 01:38 PM

Ok, so I got past the "main" hurdle, but now I have another weird issue.

So I have my code in, and have made sure my solution matches the one on pg. 168 (2nd edition). However, when I try to press F5, I now see a pop-up window that points to an exception in this part of the code:


int y = x;
x = 27;
Triangle t5 = ta[2];
ta[2].area = 343;  \\The messagebox points here.
results += "y = " + y;
MessageBox.Show(results + ", t5 area = " + t5.area);

The message says in part "NullReferenceException was unhandled" and "Object Reference was not set to an instance of the object." The window then gives me three choices, which leads to different reference text. I looked at the reference text, but it didn't seem to help me diagnose the issue (e.g., it suggested making the ta[2].area "null"). What is missing here?

#5 AndrewStellman

AndrewStellman

    Andrew Stellman

  • O'Reilly Author
  • PipPipPipPipPipPipPipPipPipPipPip
  • 811 posts
  • Gender:Male
  • Location:Brooklyn, NY
  • Interests:Author of: "Head First C#", "Beautiful Teams", "Head First PMP", "Applied Software Project Management"

Posted 12 April 2014 - 05:19 AM

It's telling you that one of your references is null, probably ta[2]. You'll learn a lot about exceptions and exception handling later in the book (chapter 10 in the second edition).
Andrew Stellman
Author, Head First C#
Building Better Software -- http://www.stellman-greene.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users