23. marts 2008 - 16:24Der er
10 kommentarer og 1 løsning
Objektreferencen er ikke indstillet til en forekomst af et objekt
Hej
Jeg kan simpelthen ikke fate hvorfor den melder ovenstående fejl:
Min kode ser ud som følgende:
For Each nodetag As XmlNode In node("tags") If Not String.IsNullOrEmpty(nodetag.InnerText.ToString) Then Dim tag As String = nodetag.InnerText.ToString Response.Write(tag & "<br/>") Movie.Tags.Add(tag) End If Next
Det er linien "movie.tags.add(tag)" der melder fejlen?
Private Function Fill() As System.Collections.Generic.List(Of Movie) Dim fileName As String = _MovieFolder + "movies.xml" If Not File.Exists(fileName) Then Return Nothing End If
Dim doc As New XmlDocument() doc.Load(fileName) Dim Movies As New List(Of Movie)()
For Each node As XmlNode In doc.SelectNodes("movies/movie") Dim Movie As New Movie() Movie.Id = New Guid(node.Attributes("id").InnerText) Movie.Title = node.Attributes("title").InnerText If node("description").InnerText IsNot Nothing Then Movie.Description = node("description").InnerText Else Movie.Description = String.Empty End If
' Tags For Each nodetag As XmlNode In node("tags") If Not String.IsNullOrEmpty(nodetag.InnerText.ToString) Then Dim tag As String = nodetag.InnerText.ToString Response.Write(tag & "<br/>") Movie.Tags.Add(tag) End If Next
Movies.Add(Movie) Next Return Movies Return Nothing End Function
<Serializable()> _ Public Class Movie Implements IComparable(Of Movie)
Public Function CompareTo(ByVal other As Movie) As Integer Implements System.IComparable(Of Movie).CompareTo Return Me.Title.CompareTo(other.Title) End Function
Public Sub New() Id = Guid.NewGuid() End Sub
Public Sub New(ByVal title As String, ByVal description As String) Me.Id = Guid.NewGuid() Me._Title = title Me._Description = description _Categories = New StateList(Of Category)() _Tags = New StateList(Of String)() End Sub
Private _Id As Guid Public Property Id() As Guid Get Return _Id End Get Set(ByVal value As Guid) _Id = value End Set End Property
Private _Title As String Public Property Title() As String Get Return _Title End Get Set(ByVal value As String) _Title = value End Set End Property
Private _Description As String Public Property Description() As String Get Return _Description End Get Set(ByVal value As String) _Description = value End Set End Property
Private _Categories As StateList(Of Category) = Nothing Public ReadOnly Property Categories() As StateList(Of Category) Get Return _Categories End Get End Property
Private _Tags As StateList(Of String) = Nothing Public ReadOnly Property Tags() As StateList(Of String) Get Return _Tags End Get End Property
Public Shared Function GetMoviesByCategory(ByVal catid As Guid) As List(Of Movie) Dim col As List(Of Movie) = Movies col.Sort() col.TrimExcess() Return col End Function
Public Shared Function GetMoviesByActor(ByVal ActorId As Guid) As List(Of Movie) Dim col As List(Of Movie) = Movies col.Sort() col.TrimExcess() Return col End Function
Public Shared Function GetMoviesByMedie(ByVal MedieId As Guid) As List(Of Movie) Dim col As List(Of Movie) = Movies col.Sort() col.TrimExcess() Return col End Function
Public Shared Function GetMovieByTag(ByVal tag As String) As List(Of Movie) Dim col As List(Of Movie) = Movies col.Sort() col.TrimExcess() Return col End Function
Public Shared Function IsTitleUnique(ByVal title As String) As Boolean For Each Movie As Movie In Movies If (Movie.Title).Equals((title), StringComparison.OrdinalIgnoreCase) Then Return False End If Next Return True End Function
Public Shared Sub Reload() _Movies = MovieManager.FillMovies() _Movies.Sort() End Sub
Public Shared Function GetMovie(ByVal id As Guid) As Movie For Each Movie As Movie In Movies If Movie.Id = id Then Return Movie End If Next Return Nothing End Function
Public Shared Sub InsertMovie(ByVal Movie As Movie) MovieManager.InsertMovie(Movie) End Sub
Public Shared Sub UpdateMovie(ByVal Movie As Movie) MovieManager.UpdateMovie(Movie) End Sub
Public Shared Sub DeleteMovie(ByVal Movie As Movie) MovieManager.DeleteMovie(Movie) End Sub
Private Shared _SyncRoot As New Object() Private Shared _Movies As List(Of Movie) Public Shared ReadOnly Property Movies() As List(Of Movie) Get If _Movies Is Nothing Then SyncLock _SyncRoot If _Movies Is Nothing Then _Movies = MovieManager.FillMovies() _Movies.Sort() End If End SyncLock End If Return _Movies End Get End Property
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.