Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid - can't access drawable nullpointer exception
    primarykey
    data
    text
    <p>I've tried to mark multiple locations on my mapview. There is, a class extends from ItemizedOverlay. There is a constructor for that which has two paramaters <code>(Drawable defaultMarker, Context c)</code> </p> <p>In the MapActivity where i have the mapview i tried to define a drawable which is necessary to create the itemized overlay object, but i always have </p> <pre><code>java.lang.NullPointerException caused by this line: Drawable marker =this.getResources().getDrawable(R.drawable.pointer); </code></pre> <p>i've checked this variable with a syso and it doesn't seems null to me</p> <pre><code>I/System.out(430): android.graphics.drawable.BitmapDrawable@405ca538 </code></pre> <p>I've tried to look after solutions. What i've found is that initalize the context in the constructor of the MapActivity</p> <p>than i've got the following error:</p> <pre><code>Unable to instantiate activity ComponentInfo: java.lang.InstantiationException MapController mc; GeoPoint p; MapView mapView; Location loc; boolean move = true; LocationManager mlocManager; LocationListener mlocListener = new MyLocationListener(); Context c /* if constructor commented: nullpointer else instantiation exception */ MapActivity(Context cc){ this.c=cc; } Drawable marker =c.getResources().getDrawable(R.drawable.pointer); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); System.out.println(this.getResources()); mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); setContentView(R.layout.map); tv = (TextView) findViewById(R.id.textView1); mapView = (MapView) findViewById(R.id.mapv); mapView.setBuiltInZoomControls(true); mc = mapView.getController(); p = new GeoPoint((int) (lat1 * 1E6), (int) (lon1 * 1E6)); Button bck = (Button) findViewById(R.id.backBtn); bck.setOnClickListener(new View.OnClickListener() { public void onClick(View vi) { mc.animateTo(p); } }); class MapOverlay extends com.google.android.maps.Overlay { public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) { super.draw(canvas, mapView, shadow); Point screenPts = new Point(); mapView.getProjection().toPixels(p, screenPts); Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.pointer); canvas.drawBitmap(bmp, screenPts.x, screenPts.y - 50, null); return true; } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload