473,473 Members | 2,262 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 1640
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Terrence | last post by:
I am doing some of the C# walkthroughs to transition from VB to C#. When I try to execute static void Main() { Aplication.Run(new Form1()) } I raise a 'System.NullReferenceException" in...
1
by: Rafael | last post by:
Hi, I hope I can find some help for this problem IDE: Visual Studio.NET 2003 Developer Editio Language: C# Problem: "An unhandled exception of type 'System.NullReferenceException' occurred in...
0
by: Matthias Kwiedor | last post by:
Hi! I want to create a WebBrowser Control at runtime. So i ported the "at start creation" of the Control to a new routine. Everything works fine, but i implement the BeforeNavigateFix and a...
3
by: msnews.microsoft.com | last post by:
actaully the code i have written below is pretty simple and short. no idea why it terminate at run-time with "An unhandled exception of type 'System.NullReferenceException' occurred" Thank you ...
2
by: fperfect13 | last post by:
Hi, I have the folowing exception Exception : System.NullReferenceException: Object reference not set to an instance of an object. 00000019 3:30:48 PM at...
2
by: Raed Sawalha | last post by:
i have a windows form(Main) with listview, when click an item in listview i open other window form (Sub) which generate the selected item from parent window in as treeview items when click any item...
1
by: msnews.microsoft.com | last post by:
I'm trying to fill an array of objects but when I add the first object I get a NullReferenceException. ----------------------------------------------------------------------------...
6
by: Joe | last post by:
Hi, I have a MS Access DB in which a record has just too many fields to be able to allow users to do inline editing in a datagrid. So I want to display as First Name: Text box where first...
3
by: Alex J. | last post by:
I just started to learn C# (my background is in C++), and right now I study the sockets, TCP/IP etc... so, I found a usefull source code at:...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.