我得到一個XAMLParseException,它真的覆蓋了另一個異常。這裏是堆棧跟蹤的一部分:
Message=Object reference not set to an instance of an object.
Source=AssignmentOrganizer
StackTrace:
at AssignmentOrganizer.MainWindow..ctor() in C:\Users\Mohit\Documents\Visual Studio 2010 \Projects\AssignmentOrganizer\AssignmentOrganizer\MainWindow.xaml.cs:line 29
這裏是第29行:對象引用未設置爲對象存儲庫的實例
lvwMain.ItemsSource = _assignmentRepo.ListAssignments();
凡lvwMain是ListView和_assignmentsRepo是一種IAssignmentRepository聲明如下:
IAssignmentRepository _assignmentRepo;
這就是錯誤發生。我正在使用存儲庫模式任何人都願意猜測?
這是我的XAML:
<Window x:Class="AssignmentOrganizer.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:toolkit="http://schemas.microsoft.com/wpf/2008/toolkit"
Title="MainWindow" Height="518" Width="755">
<DockPanel>
<Menu DockPanel.Dock="Top">
</Menu>
<ToolBar DockPanel.Dock="Top">
</ToolBar>
<StatusBar DockPanel.Dock="Bottom">
</StatusBar>
<Grid DockPanel.Dock="Left" Width="150">
<Grid.RowDefinitions>
<RowDefinition Height="259*" />
<RowDefinition Height="259*" />
</Grid.RowDefinitions>
</Grid>
<Grid DockPanel.Dock="Right" Width="150">
</Grid>
<Grid>
<ListView x:Name="lvwMain">
<ListView.View>
<GridView>
<GridViewColumn Header="Title" Width="125" />
<GridViewColumn Header="Due" Width="75" />
</GridView>
</ListView.View>
</ListView>
</Grid>
</DockPanel>
我試着將它分配給AssignmentRepository。但是_assignmentRepo並不是空的,因爲我從斷點中學到了東西。 – 2010-01-24 01:27:06
如果我刪除了設置listview項目源的代碼行,代碼運行得很好。 – 2010-01-24 03:17:45
@Mohit Deshpande:如果你確定你已經分配了'_assignmentRepo',那麼你還需要檢查'lvmMain'。 – jason 2010-01-24 20:42:46