命名空間與這兩個類都是相同的。我需要在WhatsAppSend類中調用xyz()方法。無法調用類的方法
這是我在Form1.cs方法
public void SendWhatsAppMsg()
{
try
{
WhatsAppSend ws;
ws = new WhatsAppSend(this); //Error Coming on this
ws.xyz(txtNickName.Text.ToString(),
gridSender.Rows[iCurrentChannelNo].Cells[0].Value.ToString(),
gridSender.Rows[iCurrentChannelNo].Cells[1].Value.ToString(),
CreateArrayFrom(i + 1, (i + 1) + iMsgLimitPerNo),
dropWhatsappType.SelectedItem.ToString(),
SendingData(dropWhatsappType.SelectedItem.ToString()),
ext);
}
catch(Exception e)
{
txt.log += e.ToString();
}
}
方法,我想在其他類調用WhatsAppSend.cs
namespace WhatsApp_Bulk
{
public class WhatsAppSend
{
public static WhatsAppBulk form1;
public WhatsAppSend(WhatsAppBulk _form1)
{
form1 = _form1;
}
public static String line = "";
public static String command = "";
public static string[] dst;
public static int count_sleep = Convert.ToInt32(form1.txtMsgGap.Text);
public static string WhatsAppType = "";
public static string DataToSend = "";
public static string ext = "";
public void xyz(string nickname, string sender, string password, string[] Datadst, string DataWhatsAppType, string DataDataToSend, string Dataext)
{
dst = Datadst;
WhatsAppType = DataWhatsAppType;
DataToSend = DataDataToSend;
ext = Dataext;
WhatsApp wa = new WhatsApp(sender, password, nickname, true);
}
}
}
錯誤:
System.TypeInitializationException: The type initializer for 'WhatsApp_Bulk.WhatsAppSend' threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of an object.
at WhatsApp_Bulk.WhatsAppSend..cctor() in d:\WhatsApp Bulk\WhatsApp Bulk\WhatsAppSend.cs:line 32
--- End of inner exception stack trace ---
at WhatsApp_Bulk.WhatsAppSend..ctor(WhatsAppBulk _form1)
at WhatsApp_Bulk.WhatsAppBulk.SendWhatsAppMsg() in d:\WhatsApp Bulk\WhatsApp Bulk\Form1.cs:line 367
請告訴我在哪裏出錯
在哪個行中引發異常 – vallabha 2014-10-17 06:10:42
您的設計是非常有缺陷的。您將來自實例構造函數的'WhatsAppBulk'表單實例設置爲靜態字段('form1')。想想看。 – 2014-10-17 06:16:54