473,392 Members | 1,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,392 software developers and data experts.

error: System.NullReference Exception: Object reference not set

115 100+
hi

i had developed pop3 Account mail view in my web page

but i got error in (System.NullReference Exception: Object reference not set)
NetStrm.Write(szData, 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 2059
Plater
7,872 Expert 4TB
Wouldn't you need to Connect() your TcpClient before trying to write data to it?
Mar 14 '08 #2
yogarajan
115 100+
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 Expert 4TB
hi

thanks for ur reply

can u send code

pls

thanks
...

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

thanks for ur reply

can u send code

pls

thanks
NullReferenceException 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.WriteLine 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
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...
1
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...
2
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...
1
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 =...
15
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...
4
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...
0
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...
1
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...
6
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...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.