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

  • Home
  • SEARCH
  • 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 819291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T02:17:03+00:00 2026-05-15T02:17:03+00:00

Firstly this has turned out to be quite a long post so please bear

  • 0

Firstly this has turned out to be quite a long post so please bear with me as its not too difficult but you may need to clarify something with me if i haven’t explained it correctly.
So with some help the other day from guys on this forum, i managed to partially set up my ‘mapClass’ class, but i’m having trouble with it and its not running correctly so i would like some help if possible. I will post the code below so you can see.

What Ive got is a ‘Dundrum’ class which sets up the listView for an array of items.

Then ive got a ‘dundrumSelector’ class which I use to set up the setOnClickListener() methods on the listItems and link them to their correct views.

THIS IS MY DUNDDRUM SELECTOR CLASS….

    public static final int BUTTON1 = R.id.anandaAddressButton;
public static final int BUTTON2 = R.id.bramblesCafeAddressButton;
public static final int BUTTON3 = R.id.brannigansAddressButton;

public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);

    int position = getIntent().getExtras().getInt("position");

    if(position == 0){
        setContentView(R.layout.ananda);
    };
    if(position == 1){
        setContentView(R.layout.bramblescafe);
    };
    if(position == 2){
        setContentView(R.layout.brannigans);
Button anandabutton = (Button) findViewById(R.id.anandaAddressButton);
anandabutton.setOnClickListener(new View.OnClickListener() {
    public void onClick(View view) {
        Intent myIntent = new Intent(view.getContext(),MapClass.class);
        myIntent.putExtra("button", BUTTON1);
        startActivityForResult(myIntent,0);

    }

});

Button bramblesbutton = (Button) findViewById(R.id.bramblesCafeAddressButton);
bramblesbutton.setOnClickListener(new View.OnClickListener() {

    public void onClick(View view) {
        Intent myIntent = new Intent(view.getContext(),MapClass.class);
        myIntent.putExtra("button", BUTTON2);
        startActivityForResult(myIntent, 0);
    }

});

etc etc….

Then what i did was set up static ints to represent the buttons which you can see at the top of this class, the reason for this is because in my mapClass activity I just want to have one method, because the only thing that is varying is the coordinates to each location.
ie. i dont want to have 100+ map classes essentially doing the same thing other than different coordinates into the method.

So my map class is as follows…

case DundrumSelector.BUTTON1:
        handleCoordinates("53.288719","-6.241179");
        break;
    case DundrumSelector.BUTTON2:
        handleCoordinates("53.288719","-6.241179");
        break;
    case DundrumSelector.BUTTON3:
        handleCoordinates("53.288719","-6.241179");
        break;
    }
}




private void handleCoordinates(String l, String b){


    mapView = (MapView) findViewById(R.id.mapView);
    LinearLayout zoomLayout = (LinearLayout)findViewById(R.id.zoom);
    View zoomView = mapView.getZoomControls();

    zoomLayout.addView(zoomView,
            new LinearLayout.LayoutParams(
                LayoutParams.WRAP_CONTENT, 
                LayoutParams.WRAP_CONTENT)); 
        mapView.displayZoomControls(true);

    mc = mapView.getController();
    String coordinates[] = {l, b};
    double lat = Double.parseDouble(coordinates[0]);
    double lng = Double.parseDouble(coordinates[1]);

    p = new GeoPoint(
            (int) (lat*1E6),
            (int) (lng*1E6));

    mc.animateTo(p);
    mc.setZoom(17);
    mapView.invalidate();


}

Now this is where my problem is. The onClick() events don’t even work from the listView to get into the correct views. I have to comment out the methods in ‘DundrumSelector’ before I can get into their views.

And this is what I dont understand, firstly why wont the onClick() events work, because its not even on that next view where the map is.

I know this is a very long post and it might be quite confusing so let me know if you want any clarification..

Just to recap, what i’m trying to do is just have one class that sets up the map coordinates, like what i’m trying to do in my ‘mapClass’.

Please can someone help or suggest another way of doing this!
Thanks alot everyone for reading this.

  • 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-15T02:17:03+00:00Added an answer on May 15, 2026 at 2:17 am

    The Problem ist the following:

    Button bramblesbutton = (Button) findViewById(R.id.bramblesCafeAddressButton);
    bramblesbutton.setOnClickListener(new View.OnClickListener() {
    

    Here you try to set the onClickListener to a button which is only available if you’re at position 2 and have called the correct setContentView() method. If you have another View as content (which does not contain your button) then

    Button bramblesbutton = (Button) findViewById(R.id.bramblesCafeAddressButton);
    

    will return null and in the next line there is a NullPointerException. So you have to only add this onClickListener if you’re also using the corresponding layout.

    And yes it works if you comment it out, because then you dont try to call a method on null. But on the other hand, if you comment it out, then it wont register your clicks and therefore not proceed.

    To make it even clearer:

    when your passing position 0, then you’re setting this ContentView:

    if(position == 0){
            setContentView(R.layout.ananda);
        };
    

    Therefore I assume the other two Buttons will not be in this layout anada and therefore assigning a ClickListener to them will throw a NullPointerException.

    To solve this issue and if you really need this 3 different layouts, I would do it that way (example for the first button):

    if(position == 0){
            setContentView(R.layout.ananda);
            Button anandabutton = (Button) findViewById(R.id.anandaAddressButton);
            anandabutton.setOnClickListener(new View.OnClickListener() {
                public void onClick(View view) {
                   Intent myIntent = new Intent(view.getContext(),MapClass.class);
                   myIntent.putExtra("button", BUTTON1);
                   startActivityForResult(myIntent,0);
                }
            });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This post might be a bit long, but if you think you can help,
Firstly, please don't dismiss this question - I'm aware it's an ugly situation but
Firstly I'm completely aware of this message and why it happens normally. It's not
Firstly, this is just an Object Oriented Programming question and does not apply to
Firstly, I've asked this question elsewhere , but meta.stackoverflow.com seems to think that asking
my question has two parts, but they are related. Firstly - I have Contenteditable
(Firstly, as a disclaimer, this is related to an assignment. I'm not asking anyone
Firstly, let me set out what I'd like to do. Assume I have three
After all the answers to my last question about fine-tuning turned out to be
Firstly this site is based on guests who are interested in selling their items

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.