我正在尝试在我的文件中复制粘贴后构建闹钟源代码编译时,我收到错误,mContext 无法解析。这是这段代码的链接:http: //www.netmite.com/android/mydroid/2.0/packages/apps/AlarmClock/src/com/android/alarmclock/DigitalClock.java
我已经复制粘贴了下面使用 mContext 的部分代码
protected void onAttachedToWindow() {
super.onAttachedToWindow();
if (Log.LOGV) Log.v("onAttachedToWindow " + this);
if (mAttached) return;
mAttached = true;
if (mAnimate) {
setBackgroundResource(R.drawable.animate_circle);
/* Start the animation (looped playback by default). */
((AnimationDrawable) getBackground()).start();
}
if (mLive) {
/* monitor time ticks, time changed, timezone */
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_TIME_TICK);
filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
mContext.registerReceiver(mIntentReceiver, filter, null, mHandler);
}
/* monitor 12/24-hour display preference */
mFormatChangeObserver = new FormatChangeObserver();
mContext.getContentResolver().registerContentObserver(
Settings.System.CONTENT_URI, true, mFormatChangeObserver);
updateTime();
}
private void setDateFormat() {
mFormat = Alarms.get24HourMode(mContext) ? Alarms.M24 : M12;
mAmPm.setShowAmPm(mFormat == M12);
}
为了解决这个编译错误,我把这个语句放在我的代码中
Context mContext;
但是,尽管编译错误已解决,但在模拟器中启动时,应用程序会引发异常并退出而不启动。
有人可以告诉我如何使用这个上下文的东西或我写的 wat shud 作为替代方案吗?