By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,775 Members | 1,425 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,775 IT Pros & Developers. It's quick & easy.

Object reference not set to an instance of an object.

P: n/a
Why doesn't the following code work?
I get an error at the following line...
CardGroup[0].PropertyCardType = (CardType)0;
The error is "Object reference not set to an instance of an object.", which
means the object in question have not been initiated.
But I have init the object above n this line...
public Card [] CardGroup = new Card[53];

Anybody knows how to resolve this??

Thanks :-)

namespace CardLibrary
{
public class CardFactory
{
//Create and init CardGroup
public Card [] CardGroup = new Card[53];

//Construktor
public CardFactory()
{
CardGroup[0].PropertyCardType = (CardType)0;

Console.WriteLine("Konstruktor: public CardFactory()");
}
} //Slut public class CardFactory
} //Slut namespace CardLibrary
Nov 15 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
You're trying to convert an integer to a CardType object, I would have thought it would give some sort of type mismatch error. Maybe
CardGroup[0] is null.

--
Michael Culley
"Tommy Lang" <mu*****@yahoo.se> wrote in message news:78*************************@posting.google.co m...
Why doesn't the following code work?
I get an error at the following line...
CardGroup[0].PropertyCardType = (CardType)0;
The error is "Object reference not set to an instance of an object.", which
means the object in question have not been initiated.
But I have init the object above n this line...
public Card [] CardGroup = new Card[53];

Anybody knows how to resolve this??

Thanks :-)

namespace CardLibrary
{
public class CardFactory
{
//Create and init CardGroup
public Card [] CardGroup = new Card[53];

//Construktor
public CardFactory()
{
CardGroup[0].PropertyCardType = (CardType)0;

Console.WriteLine("Konstruktor: public CardFactory()");
}
} //Slut public class CardFactory
} //Slut namespace CardLibrary

Nov 15 '05 #2

P: n/a
I'm inferring this but it looks like Card is a reference type i.e. a class

So public Card [] CardGroup = new Card[53];
will create an array that holds Card instances, but not create those
instances.

You have to loop through that array and create them:
for(int c=0;c<CardGroup.Length;c++)
CardGroup[c]=new Card();

Then CardGroup[0].PropertyCardType = (CardType)0; should work.

Richard

--
C#, .NET and Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
"Tommy Lang" <mu*****@yahoo.se> wrote in message
news:78*************************@posting.google.co m...
Why doesn't the following code work?
I get an error at the following line...
CardGroup[0].PropertyCardType = (CardType)0;
The error is "Object reference not set to an instance of an object.", which means the object in question have not been initiated.
But I have init the object above n this line...
public Card [] CardGroup = new Card[53];

Anybody knows how to resolve this??

Thanks :-)

namespace CardLibrary
{
public class CardFactory
{
//Create and init CardGroup
public Card [] CardGroup = new Card[53];

//Construktor
public CardFactory()
{
CardGroup[0].PropertyCardType = (CardType)0;

Console.WriteLine("Konstruktor: public CardFactory()");
}
} //Slut public class CardFactory
} //Slut namespace CardLibrary

Nov 15 '05 #3

P: n/a
> You're trying to convert an integer to a CardType object, I would have thought it would give some sort of type mismatch error.

My mistake, I presume CardType is an enum.

--
Michael Culley
"Michael Culley" <mc*****@NOSPAMoptushome.com.au> wrote in message news:Ot**************@tk2msftngp13.phx.gbl...
You're trying to convert an integer to a CardType object, I would have thought it would give some sort of type mismatch error. Maybe CardGroup[0] is null.

--
Michael Culley
"Tommy Lang" <mu*****@yahoo.se> wrote in message news:78*************************@posting.google.co m...
Why doesn't the following code work?
I get an error at the following line...
CardGroup[0].PropertyCardType = (CardType)0;
The error is "Object reference not set to an instance of an object.", which
means the object in question have not been initiated.
But I have init the object above n this line...
public Card [] CardGroup = new Card[53];

Anybody knows how to resolve this??

Thanks :-)

namespace CardLibrary
{
public class CardFactory
{
//Create and init CardGroup
public Card [] CardGroup = new Card[53];

//Construktor
public CardFactory()
{
CardGroup[0].PropertyCardType = (CardType)0;

Console.WriteLine("Konstruktor: public CardFactory()");
}
} //Slut public class CardFactory
} //Slut namespace CardLibrary


Nov 15 '05 #4

P: n/a
This solved my problem. I had created an array that holds Card
instances, but not created the instances themself. Card is a class and
CardType is an Enum.

Thanks,
Tommy


"Richard A. Lowe" <ch*****@yumspamyumYahoo.com> wrote in message news:<eK**************@TK2MSFTNGP09.phx.gbl>...
I'm inferring this but it looks like Card is a reference type i.e. a class

So public Card [] CardGroup = new Card[53];
will create an array that holds Card instances, but not create those
instances.

You have to loop through that array and create them:
for(int c=0;c<CardGroup.Length;c++)
CardGroup[c]=new Card();

Then CardGroup[0].PropertyCardType = (CardType)0; should work.

Richard

--
C#, .NET and Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
"Tommy Lang" <mu*****@yahoo.se> wrote in message
news:78*************************@posting.google.co m...
Why doesn't the following code work?
I get an error at the following line...
CardGroup[0].PropertyCardType = (CardType)0;
The error is "Object reference not set to an instance of an object.",

which
means the object in question have not been initiated.
But I have init the object above n this line...
public Card [] CardGroup = new Card[53];

Anybody knows how to resolve this??

Thanks :-)

namespace CardLibrary
{
public class CardFactory
{
//Create and init CardGroup
public Card [] CardGroup = new Card[53];

//Construktor
public CardFactory()
{
CardGroup[0].PropertyCardType = (CardType)0;

Console.WriteLine("Konstruktor: public CardFactory()");
}
} //Slut public class CardFactory
} //Slut namespace CardLibrary

Nov 15 '05 #5

P: n/a
You, sir, are a gentleman! Always a pleasure to help.

Richard

--
C#, .NET and Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
"Tommy Lang" <mu*****@yahoo.se> wrote in message
news:78**************************@posting.google.c om...
This solved my problem. I had created an array that holds Card
instances, but not created the instances themself. Card is a class and
CardType is an Enum.

Thanks,
Tommy


"Richard A. Lowe" <ch*****@yumspamyumYahoo.com> wrote in message

news:<eK**************@TK2MSFTNGP09.phx.gbl>...
I'm inferring this but it looks like Card is a reference type i.e. a class
So public Card [] CardGroup = new Card[53];
will create an array that holds Card instances, but not create those
instances.

You have to loop through that array and create them:
for(int c=0;c<CardGroup.Length;c++)
CardGroup[c]=new Card();

Then CardGroup[0].PropertyCardType = (CardType)0; should work.

Richard

--
C#, .NET and Complex Adaptive Systems:
http://blogs.geekdojo.net/Richard
"Tommy Lang" <mu*****@yahoo.se> wrote in message
news:78*************************@posting.google.co m...
Why doesn't the following code work?
I get an error at the following line...
CardGroup[0].PropertyCardType = (CardType)0;
The error is "Object reference not set to an instance of an object.",

which
means the object in question have not been initiated.
But I have init the object above n this line...
public Card [] CardGroup = new Card[53];

Anybody knows how to resolve this??

Thanks :-)

namespace CardLibrary
{
public class CardFactory
{
//Create and init CardGroup
public Card [] CardGroup = new Card[53];

//Construktor
public CardFactory()
{
CardGroup[0].PropertyCardType = (CardType)0;

Console.WriteLine("Konstruktor: public CardFactory()");
}
} //Slut public class CardFactory
} //Slut namespace CardLibrary

Nov 15 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.