469,927 Members | 1,672 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,927 developers. It's quick & easy.

needing help about pointers and 'System.NullReferenceException'

Hello every body,
please help me in this problem
i have written the following C# code in VS.Net and when i run the window
application i have got 'System.NullReferenceException' so please if
anybody can help reply to this message.

portion of the Code

[STAThread]
static void Main()
{
Application.Run(new Form1());
}
bool flag = false;

unsafe public class points
{
public static int[] x ;
public static int* xptr;
}

int i = 0;

unsafe private void Form1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
flag = false;
points.x = new int[i];
for(int j=0; j<i; j++)
{
points.x[j] = *(points.xptr);
points.xptr -= 1;
}
}

private void Form1_Load(object sender, System.EventArgs e)
{
i = 0;
}

private void button1_Click(object sender, System.EventArgs e)
{
textBox1.Text = Convert.ToString(points.x[0]);
textBox2.Text = points.x[1].ToString();
textBox3.Text = points.x[2].ToString();
textBox4.Text = points.x[3].ToString();
textBox5.Text = points.x[4].ToString();
textBox6.Text = points.x[5].ToString();
textBox7.Text = points.x[6].ToString();
textBox8.Text = points.x[7].ToString();
textBox9.Text = points.x[8].ToString();
textBox10.Text = Convert.ToString(points.x[9]);
}

unsafe private void Form1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
int xx = 0;
points.xptr = &xx;
flag = true;
}

unsafe private void Form1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if (flag)
{
Graphics g = CreateGraphics();
g.FillEllipse(new SolidBrush(Color.Blue),e.X,e.Y,4,4);
*(points.xptr) = e.X;
/*System.NullReferenceException*/
points.xptr += 1;
i++;
}
}

}
}

--
Message posted via http://www.dotnetmonster.com
Nov 17 '05 #1
1 1487
In which method is the exception occuring Ghada?
"Ghada Ayed via DotNetMonster.com" <fo***@nospam.DotNetMonster.com> wrote in
message news:04******************************@DotNetMonste r.com...
Hello every body,
please help me in this problem
i have written the following C# code in VS.Net and when i run the window
application i have got 'System.NullReferenceException' so please if
anybody can help reply to this message.

portion of the Code

[STAThread]
static void Main()
{
Application.Run(new Form1());
}
bool flag = false;

unsafe public class points
{
public static int[] x ;
public static int* xptr;
}

int i = 0;

unsafe private void Form1_MouseUp(object sender,
System.Windows.Forms.MouseEventArgs e)
{
flag = false;
points.x = new int[i];
for(int j=0; j<i; j++)
{
points.x[j] = *(points.xptr);
points.xptr -= 1;
}
}

private void Form1_Load(object sender, System.EventArgs e)
{
i = 0;
}

private void button1_Click(object sender, System.EventArgs e)
{
textBox1.Text = Convert.ToString(points.x[0]);
textBox2.Text = points.x[1].ToString();
textBox3.Text = points.x[2].ToString();
textBox4.Text = points.x[3].ToString();
textBox5.Text = points.x[4].ToString();
textBox6.Text = points.x[5].ToString();
textBox7.Text = points.x[6].ToString();
textBox8.Text = points.x[7].ToString();
textBox9.Text = points.x[8].ToString();
textBox10.Text = Convert.ToString(points.x[9]);
}

unsafe private void Form1_MouseDown(object sender,
System.Windows.Forms.MouseEventArgs e)
{
int xx = 0;
points.xptr = &xx;
flag = true;
}

unsafe private void Form1_MouseMove(object sender,
System.Windows.Forms.MouseEventArgs e)
{
if (flag)
{
Graphics g = CreateGraphics();
g.FillEllipse(new SolidBrush(Color.Blue),e.X,e.Y,4,4);
*(points.xptr) = e.X;
/*System.NullReferenceException*/
points.xptr += 1;
i++;
}
}

}
}

--
Message posted via http://www.dotnetmonster.com

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Terrence | last post: by
3 posts views Thread by msnews.microsoft.com | last post: by
1 post views Thread by msnews.microsoft.com | last post: by
6 posts views Thread by Joe | last post: by
3 posts views Thread by Alex J. | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.