0
當模擬輸出顯示未處理的異常時,我的應用程序總是崩潰。 我是新來的Android和C#,所以有一點耐心將不勝感激!我的代碼有什麼問題?
namespace timer2
{
[Activity(Label = "timer2", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
static Button start, stop;
static TextView time;
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
start = FindViewById<Button>(Resource.Id.start);
stop = FindViewById<Button>(Resource.Id.stop);
time = FindViewById<TextView>(Resource.Id.textView1);
SetContentView(Resource.Layout.Main);
time.Text = "00:03:00";
Counterclass timer = new Counterclass(180000, 1000);
start.Click += delegate
{
timer.Start();
};
stop.Click += delegate
{
timer.Cancel();
};
}
public class Counterclass : CountDownTimer
{
public Counterclass(long millisInFuture, long countDownInterval) :base(millisInFuture, countDownInterval)
{
}
public override void OnFinish()
{
time.Text = "Ready";
}
public override void OnTick(long millisUntilFinished)
{
long millis = millisUntilFinished;
string hms = String.Format("%02d:%02d:%02d", TimeSpan.FromMilliseconds(millis).Hours,
TimeSpan.FromMilliseconds(millis).Minutes - TimeSpan.FromHours(TimeSpan.FromMilliseconds(millis).Hours).Minutes,
TimeSpan.FromMilliseconds(millis).Seconds - TimeSpan.FromMinutes(TimeSpan.FromMilliseconds(millis).Minutes).Seconds);
time.Text = hms;
}
}
}
}
什麼是未處理的異常?你想要達到什麼目的? eplain你的問題陳述 – Viru