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 7163157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:51:17+00:00 2026-05-28T13:51:17+00:00

Im not sure why im getting NullPointerException. The method getQuestion() currently points to a

  • 0

Im not sure why im getting NullPointerException. The method getQuestion() currently points to a hard coded String for troubleshooting purposes. Im trying to generate a different string before setContentView() runs to avoid having to refresh the UI.

First I call the method getQuestion()

    TextView t=new TextView(this);
    t=(TextView)findViewById(R.id.textView4);
    try {
        //above executes well :) ... problem is below
        t.setText(quiz.getQuestion());
    } catch (Exception e1) {
        // TODO Auto-generated catch block
        Toast.makeText(AlarmReceiverActivity.this, "getQuestion() failed", Toast.LENGTH_LONG).show();
                    e1.printStackTrace();
    }

    setContentView(R.layout.main);

This is some of my Question.class:

    Question(){
    question="null";
    answer="null";
    try {
        newQuestion();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}//Question constructor

String getQuestion(){
    return "This is a question?";
}//get question
  • 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-28T13:51:18+00:00Added an answer on May 28, 2026 at 1:51 pm

    you cannot call t=(TextView)findViewById(R.id.textView4); before calling setContentView(R.layout.main);. First you need to set your layout, then findViewById can find the view from your defined layout

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

Sidebar

Related Questions

I'm not sure why I'm getting this error, but shouldn't this code compile, since
We are getting a weird issue on which we are not sure what exactly
I'm not sure if I'm missing something really obvious, but I keep getting a
I am getting unexpected T_TRY, expecting T_FUNCTION error message and am not sure as
I'm reading about connection pooling in .net and i'm not sure if i'm getting
Ok I'm working on getting better with python, so I'm not sure this is
I'm having trouble getting a JTextArea to scroll. I'm not sure how you can
I am getting an error message, and I not quite sure where the issue
I keep getting NullPointerException trying to deflate or make invisible the ViewStub from my
Not sure what I'm doing wrong, but I keep getting => #<Net::HTTPOK 200 OK

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.