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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:04:26+00:00 2026-05-23T15:04:26+00:00

I created a (very simple) class wich gets a string value from an intent.

  • 0

I created a (very simple) class wich gets a string value from an intent. If i create a Toast with the result, it’s oké. But when i try to set the text of the TextView the program stops with a NullPointerException. Eclipse gives a warning on:

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

The local variable debugView is never read

I hope someone has an idea.

public class Main extends Activity {

TextView debugView;
Button chooseOne;

Intent myIntent;

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

    TextView debugView = (TextView) findViewById(R.id.debugView);
    //debugView.setText("Hola supermercado!");

    Button ChooseOne = (Button) findViewById(R.id.chooseOne);

    ChooseOne.setOnClickListener(new OnClickListener() {

        public void onClick(View arg0) {

            myIntent = new Intent(Main.this, ResultFromSelection.class);
            myIntent.putExtra("sampleData", "This is Sample Data");
            startActivityForResult(myIntent, 1);

        }
    });

}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK && requestCode == 1) {

        String msg = data.getStringExtra("returnedData");

        //Toast.makeText(Main.this, ""+msg, Toast.LENGTH_LONG).show();
        debugView.setText(""+msg);

    }
}

}

Where i get the result from:

public class ResultFromSelection extends Activity {

 Intent intent;

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

    Intent intent= getIntent();
      intent.putExtra("returnedData", "A Value");
      setResult(RESULT_OK, intent);
    finish();
}

 }

XML From Main:

Logcat doesn’t give me any info at all, just the nullPointer. I can’t post a logcat right now because the emulator gives me some more trouble (after this briljant update >:(). Will try again when needed.

  • 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-23T15:04:27+00:00Added an answer on May 23, 2026 at 3:04 pm

    You are creating the debugView inside your oncreate which makes it a variable that only can be used there. Change

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

    to

    this.debugView = (TextView) findViewById(R.id.debugView);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i've created a very simple mysql class in c+, but when happen that mysql
I created two very simple Heroku apps to test out the service, but it's
Newbie question. I've created a very simple LoginForm class in symfony. It checks if
I created a very simple WCF class library and added this project to the
I created a very simple C++ library in xcode, it was basically: //Numbers.h class
Given a very simple object: class User { private Integer id; private String name;
I have a very simple migration which was created using the generator class AddEmailToUsers
I've created very simple REST app with next web.xml: <context-param> <param-name>resteasy.scan</param-name> <param-value>true</param-value> </context-param> <listener>
I created a very simple event publisher and it looks like this. public class
I'm using a very simple factory class to create an initialize some of my

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.