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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:33:25+00:00 2026-05-22T16:33:25+00:00

What am I doing wrong? I’ve looked at other questions and thought I was

  • 0

What am I doing wrong?

I’ve looked at other questions and thought I was doing the exact same things, but since its not working for me, obviously I’m doing something wrong!

I have my MainActivity.class that gets JSON data (coordinates) from a URL. This part works. I then want to load up a MapView, called OverlayActivity.class, and send this data to this map so I can populate it with overlays etc.
I pull varying numbers of points down and dynamically create buttons. Depending on what button is clicked, it sends different data.
Here’s the code for this loop:

final LinearLayout layout = (LinearLayout) findViewById(R.id.menuLayout);
layout.removeAllViewsInLayout();
String itemName="";
int itemID=0;
for (int i = 0; i < dataSetsMap.size(); i++) {
    itemID=i+1;
    itemName=dataSetsMap.get(itemID);
    Button b = new Button(this);
    b.setText(itemName);
    layout.addView(b);

    // These need to be final to use them inside OnClickListener()
    final String tempName=itemName;
    final int tempID=itemID;

        b.setOnClickListener(new View.OnClickListener() {
              public void onClick(View v) {
                Intent i = new Intent();
                Bundle b = new Bundle();

                i.setClass(myContext, OverlayActivity.class);
                Log.i(TAG, "Setting extras: 1:"+tempName+" and 2:"+tempID);
            b.putInt(tempName, tempID);
                i.putExtras(b);
                startActivity(i);  
              }
          });
}   // End for()

So obviously I want to read this data on the other side, assuming I’m sending it correctly. So, to read it, I’ve been trying a few different things:

        //Method 1:
    String test1=intent.getStringExtra("name");
        String test2=intent.getStringExtra("id");

    //Method 2:
        String meh=getIntent().getExtras().getString("id").toString();
        String bleh=getIntent().getExtras().getString("name");

        //Method 3:
        String value=savedInstanceState.getString("name");
        String id=savedInstanceState.getString("id").toString();

        //Method 4:
        Bundle bundle = getIntent().getExtras();
        String id=bundle.getString("id"); 
        String value = getIntent().getExtras().getString("name");

i get a NullPointerException when trying to use any of these methods. Its my first time using these types of methods so can someone point me in the right direction or tell me where I’ve gone wrong?

  • 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-22T16:33:26+00:00Added an answer on May 22, 2026 at 4:33 pm

    Firstly, using Bundle b when you’ve already got Button b isn’t really a good idea if for no other reason than it gets confusing, 😉

    Secondly, you don’t need to use a Bundle to pass a string and an int. Just add them to your Intent directly…

    Intent i = new Intent(myContext, OverlayActivity.class);
    i.putExtra("name", tempName);
    i.putExtra("id", tempID);
    startActivity(i);  
    

    To retrieve them in your OverlayActivity use…

    Intent i = getIntent();
    String name = i.getStringExtra("name");
    int id = i.getIntExtra("id", -1); // -1 in this case is a default value to return if id doesn't exist
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm doing something wrong but I do not know what. Here are my files:
What am I doing wrong? FGallery is not starting in thumbnail view? FotosGalleryViewController *vc
What am I doing wrong here. The animation slide out the navigation, but can't
What am I doing wrong? It's a very simple statement but couldn't figure out
What am I doing wrong here? why writeQuestions doesn't run on-load (not onclick..)? $(document).ready(function()
What am I doing wrong here? I'm not getting the randomNum value displayed when
So I'm doing something wrong in this python script, but it's becoming convoluted and
Am I doing something wrong or is it not possible to specify a generic
Where am i doing wrong? This is the normal print preview: But I want
I am doing something wrong and I can not figure out where... I have

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.