我收到此错误对象引用未设置为对象的实例 - Xamarin Studio 在这一行:
this line -> button.Click += delegate {
if( flag == 1)
{
return;
}
try{
int temp = Convert.ToInt16(test1.Text) ;
temp = temp * 44100 *60;
track = new IsochonicTone(temp);
track.Frequency = Convert.ToDouble(Frequencytext.Text);
track.Beat = Convert.ToDouble(Beattext.Text);
//button2.Enabled = true;
flag = 1;
ThreadPool.QueueUserWorkItem(o=> track.play());
ThreadPool.QueueUserWorkItem(o=> Stopped());
}
catch( Exception e)
{
AlertDialog.Builder builder = new AlertDialog.Builder (this);
builder.SetMessage ("Please enter a number" + e.Message);
builder.Create().Show();
}
};
这就是错误所说的:
" System.NullReferenceException:对象引用未设置为对象的实例在NeuroEntrainment.MainActivity.OnCreate(Android.OS.Bundle)[0x00074]中的c:\ Users \ E574129 \ Documents \ Projects \ Neuro-Entrainment \ Neuro-Entrainment \ MainActivity.cs:58位于/Users/builder/data/lanes/monodroid-mlion-monodroid-4.14-series/a5d57087/source/monodroid/src中的Android.App.Activity.n_OnCreate_Landroid_os_Bundle_(intptr,intptr,intptr)[0x00011] /Mono.Android/platforms/android-14/src/generated/Android.App.Activity.cs:1944 at at(wrapper dynamic-method)object.79ba1211-8361-4fb9-a6b9-821c335e23d6(intptr,intptr,intptr) "
但不是null ...并且在我将.wav文件添加到项目之前它正在工作... idk发生了什么: 这是完整的功能
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
flag = 0;
SetContentView (Resource.Layout.Main);
Button button = FindViewById<Button>(Resource.Id.myButton);
Button button2 = FindViewById<Button>(Resource.Id.button1);
EditText Frequencytext = FindViewById<EditText>(Resource.Id.Frequencytext);
EditText Beattext = FindViewById<EditText>(Resource.Id.Beattext);
EditText test1 = FindViewById<EditText>(Resource.Id.editText1);
button.Click += delegate {
if( flag == 1)
{
return;
}
try{
int temp = Convert.ToInt16(test1.Text) ;
temp = temp * 44100 *60;
track = new IsochonicTone(temp);
track.Frequency = Convert.ToDouble(Frequencytext.Text);
track.Beat = Convert.ToDouble(Beattext.Text);
flag = 1;
ThreadPool.QueueUserWorkItem(o=> track.play());
ThreadPool.QueueUserWorkItem(o=> Stopped());
}
catch( Exception e)
{
AlertDialog.Builder builder = new AlertDialog.Builder (this);
builder.SetMessage ("Please enter a number" + e.Message);
builder.Create().Show();
}
};
button2.Click += delegate {
if (track != null) {
track.stop();
track.Stop();
track.Release();
flag =0;
track = null;
}
if (_player!= null)
{
_player.Stop();
_player = null;
}
};
}
看到它不是空的 我该怎么解决这个问题?