私はこれを理解しようと約3時間を費やしています。それはとてもシンプルなようですが、私はそれを動作させるようです!誰かが私を助けてくれますか?すべて私はそれがdrawableリソースフォルダから画像を表示したいと思っています。 BitmapからDrawableに変換することはできません。BitmapをDrawableに変換できません。なぜこのエラーが発生しますか?
package com.CS3040.Places;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import com.CS3040.*;
import com.CS3040.Coursework.R;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
public class PlaceOverlayItem extends OverlayItem {
private final GeoPoint point;
private final Place place;
private final Drawable marker;
//private final Context context;
public PlaceOverlayItem(Context context, Place p, String type) {
super(p.getGeoPoint(), p.getName(), p.getFormatted_address());
if(type.equals("restaurant"))
{
//this.marker =
Bitmap bmp = BitmapFactory.decodeResource(context.getResources(), R.drawable.restaurant);
this.marker = bmp;
}
//super.setMarker(this.marker);
this.point = p.getGeoPoint();
this.place = p;
}
/**
* @return the point
*/
public GeoPoint getPoint() {
return point;
}
/**
* @return the place
*/
public Place getPlace() {
return place;
}
}
私はちょうど私がそれを試みたと言っていると私は "パブリックPlaceOverlayItem(コンテキストコンテキスト、場所p、文字列型)の空白の最終フィールドマーカーが初期化されていない可能性がありますエラーを取得しています{ スーパー(p.getGeoPoint( )、p.getName()、p.getFormatted_address()); " – user1270217
これは別のエラーです - あなたの 'if'の後に' else this.marker = null'を入れてください。 'marker'は常に値を取得します – zapl
ありがとうございました!あなたは救い主です! – user1270217