final TextView nt=(TextView)findViewById(R.id.notify);
它说,这将返回null,但indead它是在R.java和主,并与它的文本。我不知道什么是错,有什么帮助?声明TextView错误
错误:
使用NT""=(No explicit return value)
公共无效:
public void addNotification() {
if (nt.getText()==("yes")) {
NotificationManager notifier = (NotificationManager)this.
getSystemService(Context.NOTIFICATION_SERVICE);
int icon = R.drawable.icon4;
Notification notification = new Notification(icon, "Easy Settings Has Started", System.currentTimeMillis());
Intent toLaunch = new Intent(this, EasySettings.class);
PendingIntent contentIntent =
PendingIntent.getActivity(this, 0, toLaunch, 0);
notification.setLatestEventInfo(this, "Easy Settings", "Click to quickly access Easy Settings.", contentIntent);
notification.flags |= Notification.FLAG_FOREGROUND_SERVICE;
notification.flags |= Notification.DEFAULT_SOUND;
notifier.notify(0x007, notification);
} else {
if (nt.getText()==("no")) {
//do nothing
}
}
}
的OnCreate:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final TextView nt=(TextView)findViewById(R.id.notify);
try {
checkSB();
} catch (SettingNotFoundException e) {
e.printStackTrace();
}
checkRing();
checkWifi();
checkBt();
AdView adview = (AdView)findViewById(R.id.adView);
AdRequest re = new AdRequest();
re.setTesting(false);
adview.loadAd(re);
}
findViewById在使用setContentView()方法在onCreate()方法中声明时查找视图。你确定你做得对吗?也许更多的代码可以帮助。 – nhaarman 2011-05-30 17:06:39