final TextView nt=(TextView)findViewById(R.id.notify);
It says that this returns null, but indead it is in the R.java and the main and has text with it. I have no idea what is wrong, any help?
Error:
""=(No explicit return value)
Public void that uses NT:
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);
}
You need to call
setContentView()in youronCreate()method before usingfindViewById(). Here is an example of doing this…Edit
Your
ntvariable is not in the same scope as youraddNotification()method. Fix this by making it a class member or passing it into youraddNotification()method.Also, to compare strings you should really be using
.equals()not==.==checks to see if it is the same object whereas.equals()will match the text between two strings.Edit (again)
I’m going to assume you already have
ntat the class level there’s no way this would compile if not. Judging by what you’ve said, it seems your problem stems from the fact that you’re creating a separatentvariable in youronCreate(). Change your code to something like the following (I’ve stripped out the unimportant parts).If this doesn’t get you started then I’m not sure what the issue is. If this does not fix your problem you should post what you get from your
logcat.