System.NullReferenceException

Object reference not set to an instance of an object.

Page 1 of 1

11 Replies - 7471 Views - Last Post: 30 January 2010 - 11:14 PM Rate Topic: -----

#1 Johnnyy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 30-January 10

System.NullReferenceException

Posted 30 January 2010 - 06:42 AM

Hello all,

i have encountered a problem when trying to put the names that would be in capital, however i am encountering a problem that the array i'm trying to write to is giving me the error : System.NullReferenceException - Object reference not set to an instance of an object. the variable is strTemporary2, i have tried flipping them around, and excuse me if it's unprofessional i'm still just learing :o



This post has been edited by Johnnyy: 31 January 2010 - 04:56 AM


Is This A Good Question/Topic? 0
  • +

Replies To: System.NullReferenceException

#2 T.Jackson  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 97
  • Joined: 27-January 10

Re: System.NullReferenceException

Posted 30 January 2010 - 06:51 AM

Please supply entire code snippet.


Trent Jackson
Was This Post Helpful? 0
  • +
  • -

#3 Johnnyy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 30-January 10

Re: System.NullReferenceException

Posted 30 January 2010 - 06:58 AM

This is the program.



This post has been edited by Johnnyy: 31 January 2010 - 04:54 AM

Was This Post Helpful? 0
  • +
  • -

#4 T.Jackson  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 97
  • Joined: 27-January 10

Re: System.NullReferenceException

Posted 30 January 2010 - 07:04 AM

What you are getting is just a warning message.

Warning 3 Variable 'strTemporary2' is used before it has been assigned a value. A null reference exception could result at runtime. C:\Documents and Settings\Trent Jackson\Local Settings\Application Data\Temporary Projects\WindowsApplication1\Form1.vb 96 36 WindowsApplication1

Do this:
Dim strTemporary2 As String = Nothing  



Not this:
strTemporary2 = ""



Trent Jackson

This post has been edited by T.Jackson: 30 January 2010 - 07:05 AM

Was This Post Helpful? 0
  • +
  • -

#5 Johnnyy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 30-January 10

Re: System.NullReferenceException

Posted 30 January 2010 - 07:13 AM

Thank you Trent, but this has still not solved my exception, what i am trying to do is read from a file, this file which i am separating into paragraphs, these paragraphs are further separated into word by word, but i am experiencing spaces as items in my array. I think the spaces are my problem when i want to assign the capital names into the array such as WENDY would be one of the names that i would like to add to my array.

John

This post has been edited by Johnnyy: 30 January 2010 - 07:14 AM

Was This Post Helpful? 0
  • +
  • -

#6 T.Jackson  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 97
  • Joined: 27-January 10

Re: System.NullReferenceException

Posted 30 January 2010 - 07:17 AM

Don't do this either:
	Dim srobjReader As StreamReader
	Dim strPath As String
	Dim strTxt As String
	Dim strHeadstone As String
	Dim strTemp As String
	Dim arrayGraveStones As New ArrayList
	Dim arrayEveryWord() As String
	Dim arrayName() As String
	Dim intNow As Integer



This is not VB6

Do this:
	Private srobjReader As StreamReader
	Private strPath As String
	Private strTxt As String
	Private strHeadstone As String
	Private strTemp As String
	Private arrayGraveStones As New ArrayList
	Private arrayEveryWord() As String
	Private arrayName() As String
	Private intNow As Integer



Trent Jackson

View PostJohnnyy, on 30 Jan, 2010 - 06:13 AM, said:

Thank you Trent, but this has still not solved my exception, what i am trying to do is read from a file, this file which i am separating into paragraphs, these paragraphs are further separated into word by word, but i am experiencing spaces as items in my array. I think the spaces are my problem when i want to assign the capital names into the array such as WENDY would be one of the names that i would like to add to my array.

John


Then I doubt that my efforts will be useful then.

Your code RUNS fine from my end.

Perhaps someone else has a solution to this problem to shake n' run with.

Your code was tested on VB2003 (this could be the problem for the grave stones awaiting)

Shake n' RUN with what you do best.

Trent Jackson

This post has been edited by T.Jackson: 30 January 2010 - 07:18 AM

Was This Post Helpful? 0
  • +
  • -

#7 Johnnyy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 30-January 10

Re: System.NullReferenceException

Posted 30 January 2010 - 07:19 AM

So am i posting in the wrong section?

And may i ask what shake n run means? :o

Thanks for the help ;)

John

This post has been edited by Johnnyy: 30 January 2010 - 07:20 AM

Was This Post Helpful? 0
  • +
  • -

#8 T.Jackson  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 97
  • Joined: 27-January 10

Re: System.NullReferenceException

Posted 30 January 2010 - 07:28 AM

View PostJohnnyy, on 30 Jan, 2010 - 06:19 AM, said:

So am i posting in the wrong section?


Absolutely not.

Quote

And may i ask what shake n run means? :o


Oh just an old Australian figure of speech really.

Trent Jackson
Was This Post Helpful? 0
  • +
  • -

#9 Johnnyy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 30-January 10

Re: System.NullReferenceException

Posted 30 January 2010 - 07:30 AM

Haha, ok then Trent thank you for your help i will wait and see if anyone else may be able to aid me with this ;)

John
Was This Post Helpful? 0
  • +
  • -

#10 Asscotte  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 35
  • View blog
  • Posts: 610
  • Joined: 08-February 09

Re: System.NullReferenceException

Posted 30 January 2010 - 07:47 AM

To create a new object 'Direct Into Memory' (DIM) you can use the keyword new where it is supported ie.

Dim NewClass as SomeClass



but where it isn't you can use;
Dim MyString as string = ""



OR

Dim Mystring as string = String.Empty



and if you want to give it a value then you use

Dim Mystring as string = "SomeString"



and here is the catch Vb.net likes things to be a usable variable, what you are doing is creating a holder for that type and not filling it with a type that vb.net can use. Ussually when people leave a varible without a 'New' or '= Something' its because they are planning to assign it a value later, you are not doing that.


try using this line with the keyword New like it is below
Private srobjReader As New StreamReader
you will recive the error:
Overload resolution failed because no accessible 'New' accepts this number of arguments.

You need to fill out the other arguments.
Was This Post Helpful? 0
  • +
  • -

#11 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2241
  • View blog
  • Posts: 9,416
  • Joined: 29-May 08

Re: System.NullReferenceException

Posted 30 January 2010 - 08:08 AM

Johnnyy if you look in the FAQ section pinned to top the VB.net forum there is section containing links to tutorial explaining why you get this error.
Was This Post Helpful? 0
  • +
  • -

#12 Johnnyy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 30-January 10

Re: System.NullReferenceException

Posted 30 January 2010 - 11:14 PM

Thank you Adam and Asscotte, i will look into the FAQ then and see if this does solve my problem! ;)

John
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1