needing help about pointers and 'System.NullReferenceException'

  • Thread starter Ghada Ayed via DotNetMonster.com
  • Start date
G

Ghada Ayed via DotNetMonster.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;
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++;
}
}

}
}
 
G

Ghada Ayed via DotNetMonster.com

the error occurs in the parent form that calls the form which contains this
code, anyway, i have solved the problem using array list instead of
pointers.

can you help me please in creating an output text file of a window
application and save this file????
 
G

Ghada Ayed via DotNetMonster.com

the error occurs in the parent form that calls the form which contains this
code, anyway, i have solved the problem using array list instead of
pointers.

can you help me please in creating an output text file of a window
application and save this file????
 
C

Cordell Lawrence

Good. I was wondering why you chose to use pointers.
You want to save the values on the form to a file ?

Cordell Lawrence
Teleios Systems Ltd.
 

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

Top