Forum guidelines
AuthorQuestion
qualify it with a type name instead
Posted By Mark on 21 Jan 2010
Getting this error: Cannot be accessed with an instance reference, qualify it with a type name instead. Can someone tell me the code I need to get this working. I have seen other's solutions to similar problems but i'm still not getting it. The line in red letters is the problem.
 namespace TestBackground
{
public class HoneyDrops
{
public static Texture2D Texture;
public static Rectangle honeyRect;
int positionX = 0;
int positionY = 0;
int velocity;
public static HoneyDrops[] honeyDrops;
int numberOfDrops = 5;
Texture2D dropTexture;
public HoneyDrops()
{
honeyRect = new Rectangle(positionX, positionY, Texture.Width, Texture.Height);
honeyDrops = new HoneyDrops[numberOfDrops];
}


public void SetUpDrops()
{
float dropSpacing = 1440 / numberOfDrops;

for (int i = 0; i < numberOfDrops; i++)
{
honeyDrops[i].dropTexture = Texture;
honeyDrops[i].positionX += (int)(i * dropSpacing);
honeyDrops[i].positionY = 300;

}
}

public void Update()
{

for (int i = 0; i < numberOfDrops; i++)
{
honeyDrops[i].honeyRect.X = (int)honeyDrops[i].positionX;
honeyDrops[i].honeyRect.Y = (int)honeyDrops[i].positionY;
}
}


AuthorReply
Re: qualify it with a type name instead
Posted By Sam Hobbs on 22 Jan 2010  
Did you compile it? If you compile it and then press F1 on the error message or even the source code line, you will get more help. The problem is that honeyDrops is static and you are using it as if it is not static. If you look at the help for the error, the problem and solution will be obvious.

In the future, please invest the time to reduce the code you post to the minimum necessary to create the problem. Yes, it is more work for you, but it is then less work for the person trying to help you. It is what I would do if I were to ask a question, and many times I solve the problem myself when I create a small sample of a problem I am having. And don't just copy and paste code; be sure that the sample code is accurate and does in fact have the problem.

Thinking is a feeling; pleasant for some and unpleasant for others.
Re: qualify it with a type name instead
Posted By Sam Hobbs on 26 Jan 2010  
If my reply helped you, then please mark it as helpful.

Thinking is a feeling; pleasant for some and unpleasant for others.

SPONSORED BY

Custom Software Development
MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.