3

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;
}

}

thiagocfb
  • 487
  • 1
  • 9
  • 19
  • 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](http://developer.android.com/guide/topics/resources/drawable-resource.html) – Ralph Pina Jun 02 '12 at 15:40

3 Answers3

3

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.

monokh
  • 1,970
  • 3
  • 22
  • 31
  • 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 01 '12 at 16:22
  • @ThiagoCoelhoFarinazzoBalduc What is the format of the image? Also try having the image in the parent drawable folder. – monokh Jun 01 '12 at 16:27
  • My image is a png, im gonna try to put it into /Drawable and see if it works ! thanks ! – thiagocfb Jun 01 '12 at 17:05
  • sigh, still returns null the heck :/ – thiagocfb Jun 01 '12 at 17:10
  • @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 01 '12 at 17:40
  • Found what was the problem, it seems my images got corrupted somehow, thats why getDrawable was returning null ! Thanks for helping :) – thiagocfb Jun 05 '12 at 17:29
0

Try putting

import your.project.package.R;

in your imports, and make sure your R in

R.drawable.android_tiny_image

is pointing to that

m.piras
  • 345
  • 1
  • 2
  • 19
  • Still didn't work :( seriously, this doesn't make sense ! x_x http://img.photobucket.com/albums/v328/thiagoshaman/errordrawable.png See ? Eclipse itself shows that my image is there but it still returns null ! – thiagocfb Jun 01 '12 at 15:28
0

I also encountered this problem and seems to be in documentation is an explanation of the problem, if I understand correctly Resources.getDrawable()

Community
  • 1
  • 1
Siruk Viktor
  • 504
  • 1
  • 8
  • 30