Null Reference Exception on using Adobe3D Reviewer class

noobe

New member
Joined
Apr 5, 2011
Messages
3
Programming Experience
Beginner
Hello All,

I am new to programming in VB. I am trying to use the Adobe3D reviewer built in class in my code. I need to use a method of the class so I am trying to create an object. However, when I try to use the object to access the method I get this error:

System.NullReferenceException was unhandled.Object reference not set to an instance of an object.

I am not sure where I am going wrong. Any suggestions/comments will be greatly appreciated.Here is my code snippet.

VB.NET:
Module Module1
   Sub Main()
    Dim attVal As New Object
    Dim geomItemObject As Adobe3DReviewer.GeomItem
        geomItemObject = Nothing
      attVal = "value"
 //The error is thrown at this line.
   geomItemObject.AddAttribute("hi", attVal)
 
What does a NullReferenceException mean? It means that you tried to access a member of an object via a null reference, i.e. a variable that is Nothing. Can you see anywhere in your code that you have a variable that is Nothing that you try to access a member of?
 
What does a NullReferenceException mean? It means that you tried to access a member of an object via a null reference, i.e. a variable that is Nothing. Can you see anywhere in your code that you have a variable that is Nothing that you try to access a member of?

Thanks, for the reply. I tried to comment the line geomItemObject=Nothing but it didn't work.

I also, tried creating a new object using: Dim geomItemObject As New GeomItem.
However, this gave an error:'Adobe3DReviewer.GeomItemClass.Friend Sub New()' is not accessible in this context because it is 'Friend'.

I am not sure how to access a class which is 'friend'?
 
Commenting that line out will have no effect because all variables are Nothing by default, so the line is redundant anyway.

It's not the class that is declared Friend. It's the parameterless constructor. That means that it can only be used inside the assembly that it's declared in. That class must provide some other way for you to create an instance, e.g. another constructor with parameters or a factory method somewhere. An example of this is the DataRow class. You cannot create a DataRow using the New keyword because it has no accessible constructor. You have to call NewRow on a DataTable, which creates and returns the row.

You should consult the relevant documentation if you have access to it or else use Intellisense to see what members are available that look relevant. You might also look for examples online.
 
Commenting that line out will have no effect because all variables are Nothing by default, so the line is redundant anyway.

It's not the class that is declared Friend. It's the parameterless constructor. That means that it can only be used inside the assembly that it's declared in. That class must provide some other way for you to create an instance, e.g. another constructor with parameters or a factory method somewhere. An example of this is the DataRow class. You cannot create a DataRow using the New keyword because it has no accessible constructor. You have to call NewRow on a DataTable, which creates and returns the row.

You should consult the relevant documentation if you have access to it or else use Intellisense to see what members are available that look relevant. You might also look for examples online.

Thanks, once again for the reply. It was insightful.
 
Back
Top