0

I keep getting a null pointer error, but I can't figure out why. Is there something very obvious I'm missing?

final Dialog d = new Dialog(Start.this);
        // dialog.requestWindowFeature((int) Window.FEATURE_NO_TITLE);
        d.requestWindowFeature((int) android.view.Window.FEATURE_NO_TITLE);

        d.setContentView(R.layout.popuptwo);
        WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
        lp.copyFrom(d.getWindow().getAttributes());
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.MATCH_PARENT;
        d.show();

        d.getWindow().setAttributes(lp);
        TextView totaltxt = (TextView) findViewById(R.id.totaltxt);
            totaltxt.setText("Test text");

If I remove totaltxt.setText("Test text"); then the program doesn't crash. Ideas?

3
  • 1
    (but my guess is you need to call d.findViewById) Commented Nov 27, 2012 at 10:31
  • Are you sure to have totaltxt TextView in popuptwo Layout? Commented Nov 27, 2012 at 10:31
  • TextView totaltxt = (TextView) d.findViewById(R.id.totaltxt); Commented Nov 27, 2012 at 10:33

3 Answers 3

3

The text view belongs to the dialog..so you should use the dialog's view..

TextView totaltxt = (TextView) d.findViewById(R.id.totaltxt);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you guys so much. That does make sense now. I appreciate the help.
0

Just do..TextView totaltxt = (TextView) d.findViewById(R.id.totaltxt); totaltxt.setText("Test text");

Comments

0

Because it unable to get the view for dialog so,

Replace this line--

  TextView totaltxt = (TextView) findViewById(R.id.totaltxt);

by this--

  TextView totaltxt = (TextView) d.findViewById(R.id.totaltxt);

here d is your dialog object.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.