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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T02:11:37+00:00 2026-06-08T02:11:37+00:00

I’m having problems with linking the ArrayList of OverlayItems I have created in my

  • 0

I’m having problems with linking the ArrayList of OverlayItems I have created in my CustomPinpoint class to the Listview. Basically I’m trying to display the markers I added on the map in a small list. But with the code below, I get a NullPointerException error. I understand why(I think its because I create 2 seperate instances of ‘custom’ which don’t refer to each other), but I don’t understand how I can solve it…

Thank you in advance.

package com.lars.pinpoint;

import java.io.IOException;

import java.util.List;
import java.util.Locale;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;
import com.lars.pinpoint.R;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.Toast;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TabHost.OnTabChangeListener;
import android.widget.TabHost.TabContentFactory;



public class Main extends MapActivity implements OnTabChangeListener{
    /** Called when the activity is first created. */
    private static final String LIST_TAB_TAG = "List";
    private static final String MAP_TAB_TAG = "Map";

MapView map;
ListView listView;

TabHost tabHost;

long start;
long stop;
int x, y;

MyLocationOverlay compass;
MyLocationOverlay MyLoc;
MapController controller;

GeoPoint touchedPoint;
Drawable d;
List<Overlay> overlayList;
CustomPinpoint custom;



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    tabHost = (TabHost) findViewById(android.R.id.tabhost);
    tabHost.setup();

    listView = (ListView) findViewById(R.id.list);
    listView.setEmptyView((TextView) findViewById(R.id.empty));
    d = getResources().getDrawable(R.drawable.ic_launcher);
    CustomPinpoint custom = new CustomPinpoint(d,Main.this);
    listView.setAdapter(new ArrayAdapter<OverlayItem>(this, android.R.layout.simple_list_item_1, custom.pinpoints));
    listView.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            GeoPoint geoPoint = ((OverlayItem) listView.getAdapter().getItem(position)).getPoint();
            if(geoPoint != null) {

                map.getController().animateTo(geoPoint);

                tabHost.setCurrentTab(1);

        }

        }
    });

    map = (MapView) findViewById(R.id.mapview);
    map.setBuiltInZoomControls(true);
    map.postInvalidate();

    Touch t = new Touch();
    overlayList = map.getOverlays();
    overlayList.add(t);
    compass = new MyLocationOverlay(Main.this, map);
    overlayList.add(compass);
    controller = map.getController();



    MyLoc = new MyLocationOverlay(Main.this, map);
    overlayList.add(MyLoc);
    map.postInvalidate();
    MyLoc.runOnFirstFix(new Runnable() {
        public void run() {
            map.getController().animateTo(MyLoc.getMyLocation());
            }
    }); 

    tabHost.addTab(tabHost.newTabSpec(LIST_TAB_TAG).setIndicator("List").setContent(new TabContentFactory() {
        public View createTabContent(String arg0) {
            return listView;
        }
    }));
    tabHost.addTab(tabHost.newTabSpec(MAP_TAB_TAG).setIndicator("Map").setContent(new TabContentFactory() {
        public View createTabContent(String arg0) {
            return map;
        }
    }));

    //HACK to get the list view to show up first,
    // otherwise the mapview would be bleeding through and visible
    tabHost.setCurrentTab(1);
    tabHost.setCurrentTab(0);


}



@Override
protected void onPause() {
    // TODO Auto-generated method stub
    compass.disableCompass();
    super.onPause();
    MyLoc.disableMyLocation();
    finish();
}

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    compass.enableCompass();
    super.onResume();
    MyLoc.enableMyLocation();

}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}



class Touch extends Overlay {
    public boolean onTouchEvent(MotionEvent e, MapView m) {
        if (e.getAction() == MotionEvent.ACTION_DOWN) {
            start = e.getEventTime();
            x = (int) e.getX();
            y = (int) e.getY();
            touchedPoint = map.getProjection().fromPixels(x, y);

        }
        if (e.getAction() == MotionEvent.ACTION_UP) {
            stop = e.getEventTime();
        }
        if (stop - start > 1500) {
            AlertDialog alert = new AlertDialog.Builder(Main.this).create();
            alert.setTitle("Pick an option.");

            alert.setButton(DialogInterface.BUTTON_POSITIVE,"Place a pinpoint.",
                    new DialogInterface.OnClickListener() {


                        public void onClick(DialogInterface dialog,
                                int which) {
                            // TODO Auto-generated method stub

                            OverlayItem overlayItem = new OverlayItem(touchedPoint, "Pinpoint", "2nd String");
                            custom.insertPinpoint(overlayItem);
                            overlayList.add(custom);




                        }
                    });
            alert.setButton(DialogInterface.BUTTON_NEUTRAL,"Get address.",
                    new DialogInterface.OnClickListener() {


                        public void onClick(DialogInterface dialog,
                                int which) {
                            // TODO Auto-generated method stub

                        Geocoder geocoder = new Geocoder(getBaseContext(), Locale.getDefault());
                            try{

                                List<Address> address = geocoder.getFromLocation(touchedPoint.getLatitudeE6() /1E6, touchedPoint.getLongitudeE6()/1E6, 1);                          

                                if (address.size() > 0){
                                    String display = "";                                                
                                    for (int i = 0; i < address.get(0).getMaxAddressLineIndex(); i++){

                                        display += address.get(0).getAddressLine(i) + "\n";
                                    }
                                    Toast t3 = Toast.makeText(getBaseContext(), display, Toast.LENGTH_LONG);
                                    t3.show();
                                }

                            } catch (IOException e) {
                                // TODO Auto-generated catch block
                                e.printStackTrace();
                            }finally{

                            }

                        }
                    });
            alert.setButton(DialogInterface.BUTTON_NEGATIVE,"Toggle View", new DialogInterface.OnClickListener() {


                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub

                    if (map.isSatellite()){
                        map.setSatellite(false);

                    }else{

                        map.setSatellite(true);
                    }


                }
            });
            alert.show();
            return true;
        }

        return false;
    }
}




 public void gpsCurrentLocation()
 {

     tabHost.setCurrentTab(1);
     GeoPoint p = MyLoc.getMyLocation();
     map.getController().animateTo(p);

 }


// Menu XML file (menu.xml)
 @Override
 public boolean onCreateOptionsMenu(Menu menu)
 {
 MenuInflater menuInflater = getMenuInflater();
 menuInflater.inflate(R.menu.activity_main, menu);
 return true;
 }

 /**
 * Event Handling for Individual menu item selected
 * Identify single menu item by it's id
 * */

 @Override
 public boolean onOptionsItemSelected(MenuItem item)
 {

 switch (item.getItemId())
 {
 case R.id.my_location:
 Toast.makeText(Main.this, "Moving To Current location", Toast.LENGTH_SHORT).show();
 gpsCurrentLocation();

 return true;

 default:
 return super.onOptionsItemSelected(item);
 }
 }



public void onTabChanged(String tabId) {
    // TODO Auto-generated method stub

}

}

  • 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-08T02:11:39+00:00Added an answer on June 8, 2026 at 2:11 am

    Use custom = new CustomPinpoint(d,Main.this);

    instead of

      CustomPinpoint custom = new CustomPinpoint(d,Main.this);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have just tried to save a simple *.rtf file with some websites and
I have a jquery bug and I've been looking for hours now, I can't
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.

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.