473,809 Members | 2,617 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

error: System.NullRefe rence Exception: Object reference not set

115 New Member
hi

i had developed pop3 Account mail view in my web page

but i got error in (System.NullRef erence Exception: Object reference not set)
NetStrm.Write(s zData, 0, szData.Length); - this line
Expand|Select|Wrap|Line Numbers
  1. ///my code start here (cs file)
  2. using System;
  3. using System.Data;
  4. using System.Configuration;
  5. using System.Web;
  6. using System.Web.Security;
  7. using System.Web.UI;
  8. using System.Web.UI.WebControls;
  9. using System.Web.UI.WebControls.WebParts;
  10. using System.Web.UI.HtmlControls;
  11. using System.Drawing;
  12. using System.Collections;
  13. using System.ComponentModel;
  14. using System.Net;
  15. using System.Net.Sockets;
  16. using System.IO;
  17.  
  18. public partial class _Default : System.Web.UI.Page 
  19. {
  20.     public TcpClient testServername;
  21.     public NetworkStream NetStrm;
  22.     public StreamReader RdStrm;
  23.     public string Data;
  24.     public byte[] szData;
  25.     public string CRLF = "\r\n";    
  26.     protected void Page_Load(object sender, EventArgs e)
  27.     {
  28.  
  29.     }
  30.     protected void Button1_Click(object sender, EventArgs e)
  31.     {
  32.         string strpopservername = txtpopservername.Text;
  33.         string strusername = txtusername.Text;
  34.         string strpassword = txtpassword.Text;
  35.  
  36.         //Cursor cr = Cursor.Current;
  37.         //Cursor.Current = Cursors.WaitCursor;
  38.  
  39.         testServername = new TcpClient(strpopservername, 110);
  40.         //Status.Items.Clear();
  41.  
  42.         try
  43.         {
  44.             // initialization
  45.             NetStrm = testServername.GetStream();
  46.             RdStrm = new StreamReader(testServername.GetStream());
  47.             //Status.Items.Add(RdStrm.ReadLine());
  48.             //Label1.Text = Label1.Text + RdStrm.ReadLine();
  49.             ListBox1.Items.Add(RdStrm.ReadLine());
  50.  
  51.             // Login Process
  52.             Data = "USER " + strusername + CRLF;
  53.             szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
  54.             NetStrm.Write(szData, 0, szData.Length);
  55.             //Status.Items.Add(RdStrm.ReadLine());
  56.             //Label1.Text = Label1.Text + RdStrm.ReadLine();
  57.             ListBox1.Items.Add(RdStrm.ReadLine());
  58.  
  59.             Data = "PASS " + strpassword + CRLF;
  60.             szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
  61.             NetStrm.Write(szData, 0, szData.Length);
  62.             //Status.Items.Add(RdStrm.ReadLine());
  63.             //Label1.Text = Label1.Text + RdStrm.ReadLine();
  64.             ListBox1.Items.Add(RdStrm.ReadLine());
  65.  
  66.  
  67.             // Send STAT command to get information ie: number of mail and size
  68.             Data = "STAT" + CRLF;
  69.             szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
  70.             NetStrm.Write(szData, 0, szData.Length);
  71.             //Status.Items.Add(RdStrm.ReadLine());
  72.             //Label1.Text = Label1.Text + RdStrm.ReadLine();
  73.             ListBox1.Items.Add(RdStrm.ReadLine());
  74.  
  75.  
  76.             // change enabled - disabled button
  77.             Butconnect.Enabled = false;
  78.             Butdisconnect.Enabled = true;
  79.             ButRetrieve.Enabled = true;
  80.             //ConnectBtn.Enabled = false;
  81.            // DisconnectBtn.Enabled = true;
  82.            // RetrieveBtn.Enabled = true;
  83.  
  84.             // back to normal cursor
  85.             //Cursor.Current = cr;
  86.  
  87.         }
  88.         catch (InvalidOperationException err)
  89.         {
  90.             //Status.Items.Add("Error: " + err.ToString());
  91.             //Label1.Text = "Error: " + err.ToString();
  92.             ListBox1.Items.Add("Error: " + err.ToString());
  93.         }
  94.  
  95.     }
  96.     protected void Butdisconnect_Click(object sender, EventArgs e)
  97.     {
  98.  
  99.  
  100.     }
  101.     protected void ButRetrieve_Click(object sender, EventArgs e)
  102.     {
  103.         // change cursor into wait cursor
  104.         //Cursor cr = Cursor.Current;
  105.         //Cursor.Current = Cursors.WaitCursor;
  106.         string szTemp;
  107.         //Message.Clear();
  108.         Label2.Text = "";
  109.         try
  110.         {
  111.             // retrieve mail with number mail parameter
  112.             Data = "RETR " + txtnumber.Text + CRLF;
  113.             szData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray());
  114.             //NetStrm.Write(szData, 0, szData.Length);
  115.             NetStrm.Write(szData, 0, szData.Length);
  116.  
  117.             szTemp = RdStrm.ReadLine();
  118.             if (szTemp[0] != '-')
  119.             {
  120.  
  121.                 while (szTemp != ".")
  122.                 {
  123.                     Label2.Text += szTemp + CRLF;
  124.                     szTemp = RdStrm.ReadLine();
  125.                 }
  126.             }
  127.             else
  128.             {
  129.                 ListBox1.Items.Add(szTemp);
  130.             }
  131.  
  132.             // back to normal cursor
  133.             //Cursor.Current = cr;
  134.  
  135.         }
  136.         catch (InvalidOperationException err)
  137.         {
  138.             ListBox1.Items.Add("Error: " + err.ToString());
  139.         }
  140.         catch (System.Exception ex)
  141.         {
  142.             ListBox1.Items.Add("Error : " + ex.ToString());
  143.         }
  144.  
  145.     }
  146. }
  147.  
///my code end here

pls guide me

Thanks
Mar 14 '08 #1
4 2081
Plater
7,872 Recognized Expert Expert
Wouldn't you need to Connect() your TcpClient before trying to write data to it?
Mar 14 '08 #2
yogarajan
115 New Member
hi

thanks for ur reply

can u send code

pls

thanks

Wouldn't you need to Connect() your TcpClient before trying to write data to it?
Mar 15 '08 #3
Plater
7,872 Recognized Expert Expert
hi

thanks for ur reply

can u send code

pls

thanks
...

testServername. Connect()
Mar 17 '08 #4
r035198x
13,262 MVP
hi

thanks for ur reply

can u send code

pls

thanks
NullReferenceEx ception simply means that you tried to dereference a null. In that line you are dereferencing two objects. NetStr and szData. If you do a Console.WriteLi ne of those variables before the call you will see which one is null.
Mar 17 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

4
2206
by: roger | last post by:
Here's a weird one... The code below works just fine when I build in DEBUG mode. Today, I tried to build my solution in RELEASE mode, and immediately fell over this problem - apparently something in the order or sequencing or something regarding static initialization. Consider this class, which implements a singleton pattern:
1
2088
by: Andras Serfozo Jr via .NET 247 | last post by:
(Type your message here) Hello, I am having problems with a Microsoft XML example from VBat the Movies/Data and XML/Read XML Files. I created the program just like in the movie and it works up towhere the combo box gets populated. When I select a customerfrom the list it is supposed to populate text fields with theother customer info. Instead I get a Unhandled exception of Type'System.Null Reference Exception' occured / Object reference...
2
2245
by: Seth Broomer | last post by:
Can someone please tell me what might be causeing this error. I get it every once in a while. I just noticed this also...where it says c:\sethbacup\d... that is where i do my build. But then i copy over my files to a diffrent server. Why is that path not shown? thanks seth Error Message: Object reference not set to an instance of an object.
1
1267
by: kscdavefl | last post by:
When I try to display the fields associated with a table using the following code: private void fieldsButton_Click(object sender, System.EventArgs e) { string tableName = tablesList.SelectedItem.ToString(); string con = connectLabel.Text; cn = new System.Data.OleDb.OleDbConnection(con); cn.Open();
15
5372
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the path of the uploaded image, and resize it with the provided dimensions. My function is below. The current function is returning an error when run from the upload function: A generic error occurred in GDI+. Not sure what exactly that means. From what...
4
4151
by: XML newbie: Urgent pls help! | last post by:
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it verifies the login information it should display the SessionID and enable some button . I appreciate your help and thanku in advance When I run the pgm , I get the error: Can't parse login information. Namespace Manager or XsltContext needed. This query has a prefix, variable or userdefined function. I have added the Try-catch in all my functions. In...
0
1606
by: XML newbie: Urgent pls help! | last post by:
I am using VB.Net. My program is to connect to a remote IPAddress. Once, it verifies the login information it should display the SessionID and enable some button . I appreciate your help and thanku in advance When I run the pgm , I get the error: Can't parse login information. Object Reference not set to an instance of an object. I have added the Try-catch in all my functions. In ParseLoginResponse function, it catches the above...
1
4935
by: eoinmoon | last post by:
Hi all, New to C# and VS 5 and .NET. I have attempted to write a service via various examples and after several failed attempts to write an installer via the VS 5 wizards,etc I tried to install the service manually using Installutil.exe utility. Unfortunately I am getting an error very early on, during the Installation phase which has left me totally stumped as I don't know how to go about fixing this.
6
4401
by: Steve | last post by:
Hi All I have a windows forms Application (SAM) in vb.net 2008 using .net framework V2 One and only one customer out of 30 customers is getting errors daily where they have to close and restart my application, sometimes several times a day The customer has XP Home SP2
0
9721
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10376
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10120
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6881
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5689
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3861
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.