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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T03:16:00+00:00 2026-06-05T03:16:00+00:00

I was trying to learn by following the lab here https://sites.google.com/site/androidcoursearchive/labs/lab-1 Here’s the code

  • 0

I was trying to learn by following the lab here https://sites.google.com/site/androidcoursearchive/labs/lab-1

Here’s the code

NameGetter.java

public class NameGetter extends Activity implements OnClickListener {

    EditText name;
    Button submit;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.name_getter);
        name = (EditText) this.findViewById(R.id.editText1);
        submit = (Button) this.findViewById(R.id.button1);
        submit.setOnClickListener(this);
    }

    public void onClick(View v) {
        String userName = name.getText().toString();
        Intent submitIntent = new Intent(NameGetter.this, HelloWorld.class);
        submitIntent.putExtra("username", userName);
        this.startActivity(submitIntent);
    }
}

HelloWorld.java

public class HelloWorld extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        TextView tv = (TextView) this.findViewById(R.id.textViewHello);

        Bundle name = this.getIntent().getExtras();

        if(name != null) {
            String nameEntered = name.getString("username");
            if(nameEntered != null) {
                tv.setText(nameEntered);
            } else {
                tv.setText("nameEntered is null");
            }
        } else {
            tv.setText("name is null");
        }
    }
}

I can enter the text into the EditText box,and when I press submit button I get a forced close. LogCat says as following:

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mypackagerhello.com/com.mypackagerhello.com.HelloWorld}: java.lang.NullPointerException`

EDIT: Thank you all! It was the this.setContentView(R.layout.main); line that was missing from HelloWorld.java.

  • 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-06-05T03:16:02+00:00Added an answer on June 5, 2026 at 3:16 am

    Notice that in your NameGetter Activity you set the content view like so:

    this.setContentView(R.layout.name_getter);
    

    but in your HelloWorld activity you haven’t done so. Add that line right after super.onCreate and before findViewById. Good luck!

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

Sidebar

Related Questions

I am trying to learn Javascript. Here I am confused with the following code.
I'm trying to learn about grails with Google App Engine and JPA by following
While trying to learn Unity , I keep seeing the following code for overriding
I am newbie trying to learn some code. I am following the tutorial on
I am trying to learn from the code of others. I saw the following:
I'm trying to learn C#'s restrictions on an anonymous type. Consider the following code:
I am trying to learn cocos2d for iphone, following the following book http://www.apress.com/9781430233039 .
Trying to learn some geospatial python. More or less following the class notes here
i'm trying to learn codeigniter (following a book) but don't understand why the web
I'm trying to learn monotouch at the moment, and following the learn monotouch book

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.