O'Reilly Forums: Basketball Roster Wpf - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Basketball Roster Wpf

#1 User is offline   Catweezel 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 07-August 14

Posted 07 August 2014 - 05:14 AM

Hi there,

I was following the PDF replacement for the book on how to make the Basketball roster WPF app and keep getting the same error.
I'm getting this error: An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in PresentationFramework.dll

I walked through the solution and made everything the same as the solution. However I keep getting the same error. I'm stuck now and really want it to work.
Did somebody experience the same error and knows the solution. I could use some help :)
0

#2 User is offline   AndrewStellman 

  • Andrew Stellman
  • PipPipPipPipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 804
  • Joined: 08-October 08
  • Gender:Male
  • Location:Brooklyn, NY
  • Interests:Author of: "Head First C#", "Beautiful Teams", "Head First PMP", "Applied Software Project Management"

Posted 08 August 2014 - 06:16 AM

Can you post your code? One thing to check -- make sure that your project is called BasketballRoster like it says on page 750, otherwise your namespace will be different.

Just to make 100% sure, I copied and pasted all of the code for WPF BasketballRoster into a new project, and it worked just fine. So I'm sure we'll be able to get to the bottom of this! :)

Andrew



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

#3 User is offline   Catweezel 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 07-August 14

Posted 11 August 2014 - 01:36 AM

I just uploaded my basketball roster project to CodePlex. I went through the code that's on the Head First CodePlex and could not find a difference. Maybe I'm blind for it but it seems to me that it is exactly the same. I'm hoping you can solve this problem Andrew.
0

#4 User is offline   AndrewStellman 

  • Andrew Stellman
  • PipPipPipPipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 804
  • Joined: 08-October 08
  • Gender:Male
  • Location:Brooklyn, NY
  • Interests:Author of: "Head First C#", "Beautiful Teams", "Head First PMP", "Applied Software Project Management"

Posted 11 August 2014 - 02:38 PM

Here's the RosterViewModel constructor from p757 of the WPF PDF:


[size=2]public RosterViewModel(Roster roster)[/size]
{
    _roster = roster;

    Starters = new ObservableCollection<PlayerViewModel>();
    Bench = new ObservableCollection<PlayerViewModel>();

    TeamName = _roster.TeamName;

    UpdateRosters();
}[size=2]
[/size]


Here's yours: https://basketballro...terViewModel.cs

You're missing the first line of the constructor (_roster = roster), so _roster never gets set, and calling _roster.TeamName gives a NullReferenceException.


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

#5 User is offline   Catweezel 

  • New Member
  • Pip
  • Group: Members
  • Posts: 3
  • Joined: 07-August 14

Posted 11 August 2014 - 11:55 PM

Pfff how could I have missed that :unsure: And in my memory I thought I did wrote that line of code. I added the line now and the program is working.

Thanks for the help! And btw you wrote a great book Andrew. Learned a lot from it although I make some mistakes sometime :D
0

#6 User is offline   AndrewStellman 

  • Andrew Stellman
  • PipPipPipPipPipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 804
  • Joined: 08-October 08
  • Gender:Male
  • Location:Brooklyn, NY
  • Interests:Author of: "Head First C#", "Beautiful Teams", "Head First PMP", "Applied Software Project Management"

Posted 14 August 2014 - 07:51 PM

Thank you!! It's really great to hear that kind of feedback. (Feel free to post that as a five-star Amazon.com review! :) You'd be amazed at how much each review helps. Weirdly, four-star reviews aren't helpful...)

And definitely don't worry about making mistakes. In fact, in a lot of ways mistakes are actually good -- that means you're learning. I bet you'll never make that particular mistake again! :)
Andrew Stellman
Author, Head First C#
Building Better Software -- http://www.stellman-greene.com
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users