我搜索了一段时间,发现没有解决方案,或者我只是没有看到小错误?为什么我会得到NullException?
我写了一个程序使用Visual C#和有 Form1.cs的 Program.cs的 Server.cs
Server.cs
namespace WindowsApplication1 {
class testServer {
public Form1 form1;
form1.send("data");
的Program.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace WindowsApplication1
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
个
Form1.cs的
namespace WindowsApplication1
{
public partial class Form1 : System.Windows.Forms.Form
{
public Form1()
{
InitializeComponent();
}
private testServer Server;
private void startServer_Click(object sender, System.EventArgs e)
{
Server = new Server(data);
Server.form1 = this;
}
一切正常,但在Server.cs我得到form1.send("data");
一个nullexception看来form1的是真的空,但为什么呢?
我在哪里忘记了什么?
'form1.send( “数据”)在使用前初始化;'不在函数内部。 – 2012-02-22 09:12:51