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

The Archive Base Latest Questions

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

I’m trying to display markers that I have created in a MapView in a

  • 0

I’m trying to display markers that I have created in a MapView in a list.
In the class CustomPinpoint I therefore create an Arraylist of overlaysitems which I use in the Mapview to display the markers and in my Listview to sum up the different markers.
Yet when trying to setup the listview, I get the errror that I cant make a static reference to a non-static field. I get why I get this mistake, but I don’t understand or know how to fix this. (By the way, is creating a database of markers the best way to save the markers? Or are their other better ways?)

Greetings,

Main.java

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.Context;
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;




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

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

        // setup list view
        listView = (ListView) findViewById(R.id.list);
        listView.setEmptyView((TextView) findViewById(R.id.empty));

        // create some dummy coordinates to add to the list

        listView.setAdapter(new ArrayAdapter<OverlayItem>(this, android.R.layout.simple_list_item_1, CustomPinpoint.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();

        d = getResources().getDrawable(R.drawable.ic_launcher);

        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");
                                CustomPinpoint custom = new CustomPinpoint(d, Main.this);
                                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()
     {

         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

    }


}

CustomPinpoint.java

package com.lars.pinpoint;

import java.util.ArrayList;

import android.content.Context;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

public class CustomPinpoint extends ItemizedOverlay<OverlayItem>{

public ArrayList<OverlayItem> pinpoints = new ArrayList<OverlayItem>();


public CustomPinpoint(Drawable defaultMarker) {
    super(boundCenter(defaultMarker));
    // TODO Auto-generated constructor stub
}

public CustomPinpoint(Drawable m, Context context) {
    // TODO Auto-generated constructor stub
    this(m);
    Context c = context;
}

@Override
protected OverlayItem createItem(int i) {
    // TODO Auto-generated method stub
    return pinpoints.get(i);
}

@Override
public int size() {
    // TODO Auto-generated method stub
    return pinpoints.size();
}

public void insertPinpoint(OverlayItem item){
    pinpoints.add(item);
    this.populate();
}

}

PS. I’m sorry for the stupid question, but this is all relatively new for me

  • 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-08T06:37:53+00:00Added an answer on June 8, 2026 at 6:37 am

    A non-static field belongs to each instances of the class, you can’t access it from the class directly.

    So you need to either :

    • instanciate your class and access the field from the resulting
      object. In that case it might be useful to make a singleton.
    • Or declare the calling portion of code as non-static.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
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 doing a simple coin flipping experiment for class that involves flipping a
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
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
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.