所以我一直在制作这个登录应用程序(在Android上用xamarin在vis studio 17中)进行实习,而我基本上做的就是当访问者进来时,他们登录并按下标志时这样做在按钮页面打开,让他们放入他们的信息,然后(他们将他们的信息放在我将要发布的页面)它将他们的数据发送到数据库,并将他们发送回主页(应用程序从哪里开始)。我可以到达它放置所有细节和诸如此类的东西的页面,但是当按下登录时我收到此错误:
以下是我的代码: 登录:
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System.Collections.Specialized;
using MySql.Data.MySqlClient;
namespace MRC_Sign_In_Sheet
{
public class OnSignInEvenArgs : EventArgs
{
private string txtName;
private string txtRepresent;
private string txtToSee;
private string txtPurpose;
private string classification;
private string citizenStatus;
public string Name
{
get { return txtName; }
set { txtName = value; }
}
public string Represent
{
get { return txtRepresent; }
set { txtRepresent = value; }
}
public string ToSee
{
get { return txtToSee; }
set { txtToSee = value; }
}
public string Purpose
{
get { return txtPurpose; }
set { txtPurpose = value; }
}
public string CitizenStatus
{
get { return citizenStatus; }
set { citizenStatus = value; }
}
public string Classification
{
get { return classification; }
set { classification = value; }
}
public OnSignInEvenArgs(string name, string represent, string tosee, string purpose, string citizenstatus, string classification) : base()
{
Name = name;
Represent = represent;
ToSee = tosee;
Purpose = purpose;
CitizenStatus = citizenstatus;
Classification = classification;
}
}
class SignInDialog : DialogFragment
{
Button signInBack;
RadioButton radCitizen;
RadioButton radNotCitizen;
RadioButton radClassified;
RadioButton radUnclassified;
private EditText txtName;
private EditText txtRepresent;
private EditText txtToSee;
private EditText txtPurpose;
private string classification;
private string citizenStatus;
public event EventHandler<OnSignInEvenArgs> nOnSignInComplete;
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
var view = inflater.Inflate(Resource.Layout.SignIn, container, false);
txtName = view.FindViewById<EditText>(MRC_Sign_In_Sheet.Resource.Id.txtName);
txtRepresent = view.FindViewById<EditText>(MRC_Sign_In_Sheet.Resource.Id.txtRepresent);
txtToSee = view.FindViewById<EditText>(MRC_Sign_In_Sheet.Resource.Id.txtToSee);
txtPurpose = view.FindViewById<EditText>(MRC_Sign_In_Sheet.Resource.Id.txtPurpose);
radCitizen = view.FindViewById<RadioButton>(MRC_Sign_In_Sheet.Resource.Id.radCitizen);
radNotCitizen = view.FindViewById<RadioButton>(MRC_Sign_In_Sheet.Resource.Id.radNotCitizen);
radClassified = view.FindViewById<RadioButton>(MRC_Sign_In_Sheet.Resource.Id.radClassified);
radUnclassified = view.FindViewById<RadioButton>(MRC_Sign_In_Sheet.Resource.Id.radUnclassified);
signInBack = view.FindViewById<Button>(MRC_Sign_In_Sheet.Resource.Id.signInBack);
if(radCitizen.Checked)
{
citizenStatus = "Citizen";
}
else if(radNotCitizen.Checked)
{
citizenStatus = "Not A Citizen";
}
if(radClassified.Checked)
{
classification = "Classified";
}
else if (radUnclassified.Checked)
{
classification = "Unclassified";
}
signInBack.Click += SignIn_Click;
return view;
}
public override void OnActivityCreated(Bundle savedInstanceState)
{
base.OnActivityCreated(savedInstanceState);
Dialog.Window.Attributes.WindowAnimations = Resource.Style.dialog_Animations;
}
void SignIn_Click(object sender, EventArgs e)
{
int badgeNum = new Random().Next(100000, 999999);
DateTime dateTimeSignIn = DateTime.Now;
MySqlConnection con;
string connectionstring = "Server=db4free.net;Port=3306;Database=mrcwebappdb;User Id=dbeditor;Password=Monster001359%;charset=utf8";
con = new MySqlConnection(connectionstring);
con.Open();
MySqlCommand cmd = new MySqlCommand("INSERT INTO visitormanagement(visitorName,visitorBadgeNumber,visitorRepresent,visitorToSee,visitorPurpose,visitorCitizenship,visitorClassification,visitorSignIn) VALUES(@visitorName,@visitorBadgeNumber,@visitorRepresent,@visitorToSee,@visitorPurpose,@visitorCitizenship,@visitorClassification,@visitorSignIn)", con);
cmd.Parameters.AddWithValue("@visitorName", txtName.Text);
cmd.Parameters.AddWithValue("@visitorBadgeNumber", badgeNum.ToString());
cmd.Parameters.AddWithValue("@visitorRepresent", txtRepresent.Text);
cmd.Parameters.AddWithValue("@visitorToSee", txtToSee.Text);
cmd.Parameters.AddWithValue("@visitorPurpose", txtPurpose.Text);
cmd.Parameters.AddWithValue("@visitorCitizenship", citizenStatus);
cmd.Parameters.AddWithValue("@visitorVlassification", classification);
cmd.Parameters.AddWithValue("@visitorSignIn", dateTimeSignIn.ToString());
cmd.ExecuteNonQuery();
nOnSignInComplete.Invoke(this, new OnSignInEvenArgs(txtName.Text, txtRepresent.Text, txtToSee.Text, txtPurpose.Text, citizenStatus, classification));
this.Dismiss(); //This brings me back to the home page
}
}
}
这是我目前得到的错误:未处理的异常:
System.TypeInitializationException:'MySql.Data.MySqlClient.Replication.ReplicationManager'的类型初始值设定项引发异常。发生
btw:我正在使用该db4free站点仅用于测试目的,因为如果我将它放入本地托管的数据库中,该位置将是服务器的特定地址。我意识到错误(如果我没有弄错)与打开连接时有关,或者我可能直接完全完全错误。对此的任何帮助将不胜感激。
快速更新:所以我意识到我正在做一种 expletive 向后的方法来将它连接到数据库。现在它连接但是在提交时,我收到了这个新错误。以下是截至目前的代码(首先是登录,第二是签出)。
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System.Collections.Specialized;
using MySqlConnector;
using MySql.Data.MySqlClient;
namespace MRC_Sign_In_Sheet
{
class SignInDialog : DialogFragment
{
Button signInBack;
RadioButton radCitizen;
RadioButton radNotCitizen;
RadioButton radClassified;
RadioButton radUnclassified;
private EditText txtName;
private EditText txtRepresent;
private EditText txtToSee;
private EditText txtPurpose;
private string classification;
private string citizenStatus;
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
var view = inflater.Inflate(Resource.Layout.SignIn, container, false);
txtName = view.FindViewById<EditText>(MRC_Sign_In_Sheet.Resource.Id.txtName);
txtRepresent = view.FindViewById<EditText>(MRC_Sign_In_Sheet.Resource.Id.txtRepresent);
txtToSee = view.FindViewById<EditText>(MRC_Sign_In_Sheet.Resource.Id.txtToSee);
txtPurpose = view.FindViewById<EditText>(MRC_Sign_In_Sheet.Resource.Id.txtPurpose);
radCitizen = view.FindViewById<RadioButton>(MRC_Sign_In_Sheet.Resource.Id.radCitizen);
radNotCitizen = view.FindViewById<RadioButton>(MRC_Sign_In_Sheet.Resource.Id.radNotCitizen);
radClassified = view.FindViewById<RadioButton>(MRC_Sign_In_Sheet.Resource.Id.radClassified);
radUnclassified = view.FindViewById<RadioButton>(MRC_Sign_In_Sheet.Resource.Id.radUnclassified);
signInBack = view.FindViewById<Button>(MRC_Sign_In_Sheet.Resource.Id.signInBack);
if (radCitizen.Checked)
{
citizenStatus = "Citizen";
}
else if (radNotCitizen.Checked)
{
citizenStatus = "Not A Citizen";
}
if (radClassified.Checked)
{
classification = "Classified";
}
else if (radUnclassified.Checked)
{
classification = "Unclassified";
}
signInBack.Click += SignIn_Click;
return view;
}
public override void OnActivityCreated(Bundle savedInstanceState)
{
base.OnActivityCreated(savedInstanceState);
Dialog.Window.Attributes.WindowAnimations = Resource.Style.dialog_Animations;
}
void SignIn_Click(object sender, EventArgs e)
{
int badgeNum = new Random().Next(100000, 999999);
DateTime dateTimeSignIn = DateTime.Now;
MySqlConnection con = new MySqlConnection("Server=db4free.net;Port=3306;Database=mrcwebappdb;Uid=dbeditor;pwd=Monster001359%;");
string insertQuery = "INSERT INTO visitormanagement(visitorName, visitorBadgeNumber, visitorRepresent, visitorToSee, visitorPurpose, visitorCitizenship, visitorClassification, visitorSignIn) VALUES('" + txtName.Text + "','" + badgeNum + "'," + txtRepresent.Text + "','" + txtToSee.Text + "','" + txtPurpose.Text + "','" + citizenStatus + "','" + classification + "','" + dateTimeSignIn + ")";
con.Open();
MySqlCommand command = new MySqlCommand(insertQuery, con);
command.ExecuteNonQuery();
con.Close();
this.Dismiss();
}
}
}
退出:
using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using System.Collections.Specialized;
using MySqlConnector;
using MySql.Data.MySqlClient;
namespace MRC_Sign_In_Sheet
{
class SignOutDialog : DialogFragment
{
Button signOutBack;
private EditText signOutName;
private EditText signOutBadge;
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
base.OnCreateView(inflater, container, savedInstanceState);
var view = inflater.Inflate(Resource.Layout.SignOut, container, false);
signOutName = view.FindViewById<EditText>(MRC_Sign_In_Sheet.Resource.Id.signOutName);
signOutBadge = view.FindViewById<EditText>(MRC_Sign_In_Sheet.Resource.Id.signOutBadge);
signOutBack = view.FindViewById<Button>(MRC_Sign_In_Sheet.Resource.Id.signOutBack);
signOutBack.Click += SignOut_Click;
return view;
}
public override void OnActivityCreated(Bundle savedInstanceState)
{
base.OnActivityCreated(savedInstanceState);
Dialog.Window.Attributes.WindowAnimations = Resource.Style.dialog_Animations;
}
void SignOut_Click(object sender, EventArgs a)
{
DateTime dateTimeSignOut = DateTime.Now;
MySqlConnection con = new MySqlConnection("Server=db4free.net;Port=3306;Database=mrcwebappdb;Uid=dbeditor;pwd=Monster001359%;");
string insertQuery = "INSERT INTO visitormanagementsignout(visitorName, visitorBadgeNumber, visitorSignOutTime) VALUES('" + signOutName.Text + "','" + signOutBadge + "'," + dateTimeSignOut + ")";
con.Open();
MySqlCommand command = new MySqlCommand(insertQuery, con);
command.ExecuteNonQuery();
con.Close();
this.Dismiss();
}
}
}
我在输出中得到这个 “未处理的例外:
System.AggregateException:发生了一个或多个错误。“之后没有更多信息。我查看了调试,这是我登录的一个集合,然后退出了。下面是两个调试错误的位置发生。
On Sign In
-----------------------------------------------------
Unhandled Exception:
System.AggregateException: One or more errors occurred.
05-21 17:52:39.623 D/Mono (12745): Image addref System.Runtime.Serialization[0xf8223678] -> System.Runtime.Serialization.dll[0xf8222e88]: 2
05-21 17:52:39.623 D/Mono (12745): Prepared to set up assembly 'System.Runtime.Serialization' (System.Runtime.Serialization.dll)
05-21 17:52:39.623 D/Mono (12745): Assembly System.Runtime.Serialization[0xf8223678] added to domain RootDomain, ref_count=1
05-21 17:52:39.624 D/Mono (12745): AOT: image 'System.Runtime.Serialization.dll.so' not found: dlopen failed: library "/data/app/MRC_Sign_In_Sheet.MRC_Sign_In_Sheet-1/lib/arm/libaot-System.Runtime.Serialization.dll.so" not found
05-21 17:52:39.625 D/Mono (12745): AOT: image '/usr/local/lib/mono/aot-cache/arm/System.Runtime.Serialization.dll.so' not found: dlopen failed: library "/data/app/MRC_Sign_In_Sheet.MRC_Sign_In_Sheet-1/lib/arm/libaot-System.Runtime.Serialization.dll.so" not found
05-21 17:52:39.625 D/Mono (12745): Config attempting to parse: 'System.Runtime.Serialization.dll.config'.
05-21 17:52:39.625 D/Mono (12745): Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Runtime.Serialization/System.Runtime.Serialization.config'.
05-21 17:52:39.626 D/Mono (12745): Assembly Ref addref Mono.Android[0xf7a39d78] -> System.Runtime.Serialization[0xf8223678]: 2
05-21 17:52:39.626 D/Mono (12745): Assembly Ref addref System.Runtime.Serialization[0xf8223678] -> mscorlib[0xf79f65c8]: 23
05-21 17:52:43.443 I/Kernel (12745): [303182.603650] <0> (0)[12801:Timer-Scheduler][name:ion&][ION]warning: release handle @ client destroy: handle=ffffffc0290649c0, buf=ffffffc0049b2800, ref=4, size=3891200, kmap=0
05-21 17:52:43.443 I/Kernel (12745): [303182.603679] <0> (0)[12801:Timer-Scheduler][name:ion&][ION]warning: release handle @ client destroy: handle=ffffffc003519f80, buf=ffffffc038f00500, ref=2, size=3891200, kmap=0
05-21 17:52:43.443 I/Kernel (12745): [303182.603696] <0> (0)[12801:Timer-Scheduler][name:ion&][ION]warning: release handle @ client destroy: handle=ffffffc02f609540, buf=ffffffc039616000, ref=4, size=3891200, kmap=0
05-21 17:52:43.443 I/Kernel (12745): [303182.603741] <0> (0)[12801:Timer-Scheduler][name:ion&][ION]warning: release handle @ client destroy: handle=ffffffc03a96f080, buf=ffffffc039616e00, ref=2, size=3891200, kmap=0
05-21 17:52:43.443 I/Kernel (12745): [303182.603757] <0> (0)[12801:Timer-Scheduler][name:ion&][ION]warning: release handle @ client destroy: handle=ffffffc029064c00, buf=ffffffc03b5b2b00, ref=8, size=3833856, kmap=0
______________________________________________________
On Sign Out
------------------------------------------------------
Unhandled Exception:
System.AggregateException: One or more errors occurred.
05-21 17:51:25.292 D/Mono (12603): Image addref System.Runtime.Serialization[0xf81e7578] -> System.Runtime.Serialization.dll[0xf8213c30]: 2
05-21 17:51:25.292 D/Mono (12603): Prepared to set up assembly 'System.Runtime.Serialization' (System.Runtime.Serialization.dll)
05-21 17:51:25.292 D/Mono (12603): Assembly System.Runtime.Serialization[0xf81e7578] added to domain RootDomain, ref_count=1
05-21 17:51:25.293 D/Mono (12603): AOT: image 'System.Runtime.Serialization.dll.so' not found: dlopen failed: library "/data/app/MRC_Sign_In_Sheet.MRC_Sign_In_Sheet-1/lib/arm/libaot-System.Runtime.Serialization.dll.so" not found
05-21 17:51:25.294 D/Mono (12603): AOT: image '/usr/local/lib/mono/aot-cache/arm/System.Runtime.Serialization.dll.so' not found: dlopen failed: library "/data/app/MRC_Sign_In_Sheet.MRC_Sign_In_Sheet-1/lib/arm/libaot-System.Runtime.Serialization.dll.so" not found
05-21 17:51:25.294 D/Mono (12603): Config attempting to parse: 'System.Runtime.Serialization.dll.config'.
05-21 17:51:25.294 D/Mono (12603): Config attempting to parse: '/usr/local/etc/mono/assemblies/System.Runtime.Serialization/System.Runtime.Serialization.config'.
05-21 17:51:25.294 D/Mono (12603): Assembly Ref addref Mono.Android[0xf7a39ac0] -> System.Runtime.Serialization[0xf81e7578]: 2
05-21 17:51:25.295 D/Mono (12603): Assembly Ref addref System.Runtime.Serialization[0xf81e7578] -> mscorlib[0xf79f6318]: 23
Loaded assembly: System.Runtime.Serialization.dll [External]
05-21 17:51:31.753 I/Kernel (12603): [303110.913251] <0> (0)[12665:Timer-Scheduler][name:ion&][ION]warning: release handle @ client destroy: handle=ffffffc01c34b080, buf=ffffffc02ec3ad00, ref=4, size=3891200, kmap=0
05-21 17:51:31.753 I/Kernel (12603): [303110.913288] <0> (0)[12665:Timer-Scheduler][name:ion&][ION]warning: release handle @ client destroy: handle=ffffffc031b94400, buf=ffffffc03703e600, ref=4, size=3891200, kmap=0
05-21 17:51:31.753 I/Kernel (12603): [303110.913313] <0> (0)[12665:Timer-Scheduler][name:ion&][ION]warning: release handle @ client destroy: handle=ffffffc046020d00, buf=ffffffc0370c2a00, ref=2, size=3891200, kmap=0
05-21 17:51:31.753 I/Kernel (12603): [303110.913339] <0> (0)[12665:Timer-Scheduler][name:ion&][ION]warning: release handle @ client destroy: handle=ffffffc046020840, buf=ffffffc0370c2c00, ref=2, size=3891200, kmap=0
05-21 17:51:31.753 I/Kernel (12603): [303110.913364] <0> (0)[12665:Timer-Scheduler][name:ion&][ION]warning: release handle @ client destroy: handle=ffffffc01c1f47c0, buf=ffffffc03b5b2b00, ref=8, size=3833856, kmap=0
世界上究竟是什么造成了这种情况?