2012-06-01 33 views
3

,因爲我已經打掉我對於這件事的最後一個問題是由於發佈關於我要去用正確的密碼再次嘗試這個問題從一個不同的代碼......getDrawable返回null

所以這裏的處理,我一直在使用Android的GoogleMaps API進行一些測試,當我嘗試在我的地圖上使用我的一張圖像設置CustomItemizedOverlay時,我注意到當我使用getDrawable訪問我的圖像時,它返回null即使日食本身顯示我我的形象是在那裏,當我使用CTRL +退格時,選擇哪個可繪製我希望進入:/

因爲這個我一直在我的頭穿過牆。這裏有什麼問題的任何線索?

感謝提前:)

PS:可見日食打印顯示的資源裏面我的形象時,我用ctrl + Backspace鍵http://img.photobucket.com/albums/v328/thiagoshaman/errordrawable.png

代碼:

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

}

+0

你使用你的形象的延伸比png格式,JPG格式,或.gif等?它可能無法識別其他擴展類型。 [http://developer.android.com/guide/topics/resources/drawable-resource.html](http://developer.android.com/guide/topics/resources/drawable-resource.html) –

+0

Nope :(它的一個PNG:/ – thiagocfb

回答

3

嘗試具有的所有素質繪製的文件夾中的圖像(繪製-HDPI /提拉 - LDPI等)

可能是您使用的模擬器或設備具有不同的密度,並且正試圖從另一個文件夾中拉出圖像。

+0

嗯好意思!試過,但現在仍然不工作:/和問題不影響1圖像,我不能達到我的資源內的任何圖像,從來沒有見過這種情況發生之前:/ – thiagocfb

+0

@ThiagoCoelhoFarinazzoBalduc圖像的格式是什麼?也可以嘗試在父級可繪製文件夾中有圖像。 – Monokh

+0

我的圖像是一個PNG,我會嘗試將它放入/可繪製並查看它是否可用!謝謝! – thiagocfb

0

嘗試把

import your.project.package.R; 

在你的進口,並確保您在

R.drawable.android_tiny_image 

R爲指向該

+0

仍然沒有工作:(嚴重,這沒有任何意義!x_x http://img.photobucket.com/albums/v328/thiagoshaman/errordrawable.png請參閱?Eclipse本身顯示我的圖片在那裏,但它仍然返回null! – thiagocfb