Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5976949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:18:02+00:00 2026-05-22T21:18:02+00:00

final TextView nt=(TextView)findViewById(R.id.notify); It says that this returns null, but indead it is in

  • 0
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);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:18:03+00:00Added an answer on May 22, 2026 at 9:18 pm

    You need to call setContentView() in your onCreate() method before using findViewById(). Here is an example of doing this…

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        // Set this to whatever your layout is
        setContentView(R.layout.main);
    
        // Now you can call the activity's findViewById() method...
        TextView nt = (TextView)findViewById(R.id.notify);
    }
    

    Edit
    Your nt variable is not in the same scope as your addNotification() method. Fix this by making it a class member or passing it into your addNotification() 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 nt at 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 separate nt variable in your onCreate(). Change your code to something like the following (I’ve stripped out the unimportant parts).

    public class YourActivity extends Activity {
    
        private TextView nt;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            // Do not create a new instance, use the one you have...
            nt = (TextView)findViewById(R.id.notify);
    
            // Do whatever you were doing...
        }
    
        public void addNotification() {
            // This *should* work...
            if (nt.getText().equals("yes")) {
                // Do whatever you were doing...
            }
            else if (nt.getText().equals("no")) {
                // Do nothing...
            }
        }
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

final TextView dob = (TextView) findViewById(R.id.TextView_DOB); DatePickerDialog dateDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {
public void startGameButtonClicked(View view) { final TextView shadow = (TextView) findViewById(R.id.main_menu_start_game_button_shadow); final Animation animation
Humm... I can do this easily in Java (and all other languages) but, it
I am trying to change text when an action occurs using: final TextView textViewToChange
public void getDataPermission() { final TextView twCheck = (TextView) findViewById(R.id.textView1); final TextView twPackageInfo =
Final question for the night. And apologies for the complete noobness of this. I
So the final menu will look something like this: Item B Item B-1 Item
While making some final tests of a class-library that I'm writing for Windows Mobile
In this opportunity I try to do a simple activity that get a EditText
This is my code: how to write the java code display the one by

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.