DJSTU

I keep getting problems with listview controls sometimes it runs fine sometimes it dont, the line ive highlighted below in yellow is the line that sometimes causes the exception, hopefully someone could explain.

Code Block

Public Sub loadplayer1()

If Mainform.player1.playState = WMPLib.WMPPlayState.wmppsPlaying Then

MsgBox("Player Currently Active", MsgBoxStyle.Information)

ElseIf Mainform.Playlist1.Items.Count > 0 Then

Mainform.player1.URL = Mainform.Playlist1.Items(0).SubItems(2).Text

Mainform.P1tracklabel.Text = (Mainform.player1.currentMedia.name)

Mainform.P1TotalLabel.Text = (Mainform.Playlist1.Items(0).SubItems(1).Text)

Mainform.P1Progressbar.Style = ProgressBarStyle.Blocks

Mainform.P1Progressbar.Value = 0

Mainform.Playlist1.Items.Remove(Mainform.Playlist1.Items(0))

End If

End Sub




Re: Visual Basic Express Edition Object Null Reference

bdbodger

does this work any different

Code Block

Mainform.Playlist1.removeItem(Mainform.Playlist1.Item(0))

oh wait sorry in your example playlist1 is a listview Maybe this is what you need

Code Block

Mainform.Playlist1.items(0).remove

Are you creating a media player playlist such as this

Code Block

Dim Playlist As IWMPPlaylist = Nothing

Playlist = player.newPlaylist("vegas", "")

Playlist.appendItem(player.newMedia(My.Computer.FileSystem.SpecialDirectories.MyMusic & "\Elvis 2nd To None\19 - Viva Las Vegas.mp3")) ' single song

Dim song As String() = Directory.GetFiles(My.Computer.FileSystem.SpecialDirectories.MyMusic & "\Elvis 2nd To None", "*.mp3")

For Each s As String In song

Playlist.appendItem(player.newMedia(s))

Next

player.currentPlaylist = Playlist

player.Ctlcontrols.play()





Re: Visual Basic Express Edition Object Null Reference

DJSTU

still sometimes only working getting error "Object reference not set to an instance of an object."






Re: Visual Basic Express Edition Object Null Reference

DJSTU

Can anyone give some Idea's atall would be very apreciated im at a stand still at the minute with my application.






Re: Visual Basic Express Edition Object Null Reference

Omar Abid

This error come when VB don't find something to do an action.

Make sure that all works well and there's no missing thing






Re: Visual Basic Express Edition Object Null Reference

DJSTU

Yep I know that thanks Omar, Object Null reference, Its tying to pull data from a source that has no data.... The trouble is it does have the data, its and intermitent problem, Sometimes it works sometimes it doesn't.... So i should imagine its something to do with the focused control on the form, But otherwise I really dont know whats causing it.






Re: Visual Basic Express Edition Object Null Reference

Kea

Use ListControl.RemoveAt(0) (I didn't check if it has, but I expect it to).




Re: Visual Basic Express Edition Object Null Reference

ReneeC

It has to do with an object not being instantiated or not having received a typed pointer to an object.

DJ.... do you use the debugger






Re: Visual Basic Express Edition Object Null Reference

DJSTU

Hi Renee,

I have used step into and taken note of what is says in the imediate window, it gives me this:

A first chance exception of type 'System.NullReferenceException' occurred in System.Windows.Forms.dl

Code Block

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click

If searchlist.Focus = True Then

If searchlist.Items.Count > 0 Then

m_audio = New Audio(searchlist.SelectedItems(0).SubItems(2).Text, False) ' to make track duration

Dim t As New TimeSpan(0, 0, m_audio.Duration)

Dim itm As ListViewItem = searchlist.SelectedItems(0)

With Playlist1.Items.Add(searchlist.SelectedItems(0).Text)

.SubItems.Add(t.ToString)

.SubItems.Add(searchlist.SelectedItems(0).SubItems(2).Text)

.StateImageIndex = 1

End With

searchlist.SelectedItems(0).Remove()

End If

End If

End Sub






Re: Visual Basic Express Edition Object Null Reference

ReneeC

" have used step into and taken note of what is says in the imediate window, it gives me this:"

Have you ever used the debugger and looked at an object






Re: Visual Basic Express Edition Object Null Reference

DJSTU

think im going to have to hold my hands up and say no.....






Re: Visual Basic Express Edition Object Null Reference

ReneeC

Good that's progress !

Want to see what you are missing I'll give you a mini-lesson here. We'll use a class like Point if you are interested.






Re: Visual Basic Express Edition Object Null Reference

DJSTU

yep sure that would be great, I would like to understand what the problem is






Re: Visual Basic Express Edition Object Null Reference

ReneeC

Start a new windows APP. Create a Form load event. In the event place this one line:

Dim p as point = me.loc

end sub ' Place a break point here and hit the little green triangle. The program will run to the end sub and stop exection.

place your cursor on p and left click. Tell me what you see.......






Re: Visual Basic Express Edition Object Null Reference

DJSTU

p = {X = 44 Y = 58}

this is what it gives me I can understand its putting the data into the variable P correct