Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Since i've busted my last question regarding this matter due to posting a different code from the one regarding the problem i'm going to try again with the right code...

So here's the deal, I've been running some tests with GoogleMaps API for Android and when i was trying to set up an CustomItemizedOverlay on my map using one of my images, i've noticed that when i was using getDrawable to access my image it was returning null even tho eclipse itself shows me my image is there when i use ctrl+backspace when selecting which drawable i wish to acess :/

I've been busting my head through the wall for hours because of this. Any clues on what's wrong here?

Thanks in advance :)

PS: print showing that eclipse shows my image inside resources when i use ctrl + backspace http://img.photobucket.com/albums/v328/thiagoshaman/errordrawable.png

Code:

import java.util.List;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
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.Overlay;
import com.google.android.maps.OverlayItem;
public class MapHandlerActivity extends MapActivity {
private MapView mapView;
private static final int latitudeE6 = 37985339;
private static final int longitudeE6 = 23716735;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.main);
    setContentView(R.layout.maphandler);
    mapView = (MapView) findViewById(R.id.map_view);      
    mapView.setBuiltInZoomControls(true);
    List<Overlay> mapOverlays = mapView.getOverlays();
    Resources res = this.getResources();
    Drawable drawable = res.getDrawable(R.drawable.android_tiny_image);
    CustomItemizedOverlay itemizedOverlay = new CustomItemizedOverlay(drawable, this);
    GeoPoint point = new GeoPoint(latitudeE6, longitudeE6);
    OverlayItem overlayItem = new OverlayItem(point, "Olá", "Estou em Athena, Grécia!");
    itemizedOverlay.addOverlay(overlayItem);
    mapOverlays.add(itemizedOverlay);
    MapController mapController = mapView.getController();
    mapController.animateTo(point);
    mapController.setZoom(6);
@Override
protected boolean isRouteDisplayed() {
    return true;
                Are you using an extension in your image other than .png, .jpg, or .gif? It might not recognize other extension types. http://developer.android.com/guide/topics/resources/drawable-resource.html
– Ralph Pina
                Jun 2, 2012 at 15:40

Try having the image in all drawable qualities folders (drawable-hdpi/drawable-ldpi etc.)

Could be that the emulator or device your using has a different density and is trying to pull images from another folder.

Hmm good ideia ! Tried that right now but still not working :/ and the problem isn't affecting 1 image, i can't reach any image inside my resources, never seen this happen before :/ – thiagocfb Jun 1, 2012 at 16:22 @ThiagoCoelhoFarinazzoBalduc What is the format of the image? Also try having the image in the parent drawable folder. – monokh Jun 1, 2012 at 16:27 @ThiagoCoelhoFarinazzoBalduc That is really weird. Step through it in the debugger. Make sure getResources() is actually returning and have a look through what it returns to see if you can find your drawable. – monokh Jun 1, 2012 at 17:40 Still didn't work :( seriously, this doesn't make sense ! x_x img.photobucket.com/albums/v328/thiagoshaman/errordrawable.png See ? Eclipse itself shows that my image is there but it still returns null ! – thiagocfb Jun 1, 2012 at 15:28

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.