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