use of unassigned local variable - object can't be null though

  • Thread starter Thread starter Doug
  • Start date Start date
D

Doug

I am trying to work with an object and create it like so:

EXTRA.Sessions oSessions = new EXTRA.Sessions();

This doesn't work because I get this error:

'Cannot create an instance of the abstract class or interface
'EXTRA.Sessions'.'

So I try to do this:

EXTRA.Sessions oSessions;
oSessions.Open(strSession);

Then I get this error:

'use of unassigned local variable oSessions'

So I try this:

EXTRA.Sessions oSessions = null;
oSessions.Open(strSession);

and I get this error:

'Object reference not set to an instance of an object.'

So it's like I don't have a way to create this object. Is there some
other way to do this that I'm missing?
 
So it's like I don't have a way to create this object. Is there some
other way to do this that I'm missing?

It is apparent from the error messages you are getting that EXTRA.Sessions
is marked as an abstract class; therefore you cannot instantiate it. You
have to derive from it and override the abstract methods in the derived
class; then you can instantiate that derived class.

Joanna
 
The first error message gives you the best clue. It looks like Sessions
class is abstract and abstract classes cannot be instantiated with new.
Thus, you have to subclass the Sessions (in c# by saying class MyClass :
EXTRA.Sessions, or in VB.NET i think that is class MyClass implements
EXTRA.Sessions). And then instantiate MyClass (of course only after
implementing abstract Sessions class parts.

Also, sessions class might have never been meant to be instantiated.
Look for classes that implement this abstract class and use them instead.

L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top