我正在开发和Android应用程序,其中我必须使用谷歌地图API。我必须在特定位置(纬度和经度)的标记上显示气球信息。我成功地获得了经纬度。对于显示baloon的叠加层我使用CustomItemizedOverlay但是我收到NoClassDefFoundError错误。
这是我想要实现的图片
以下是名为BTAddLocation的类的代码。
CustomItemizedOverlay<CustomOverlayItem> itemizedOverlay;
drawable = getResources().getDrawable(R.drawable.mark_red);
itemizedOverlay = new CustomItemizedOverlay<CustomOverlayItem>(
drawable, mapView);
CustomOverlayItem overlayItem = new CustomOverlayItem(geoPoint,
name, getArea(),
index);
itemizedOverlay.addOverlay(overlayItem);
mapOverlays.add(itemizedOverlay);
我在第3行遇到错误。错误是
07-19 19:57:21.194: E/AndroidRuntime(8764): java.lang.NoClassDefFoundError: com.colony.radar.CustomItemizedOverlay
07-19 19:57:21.194: E/AndroidRuntime(8764): at com.colony.radar.BTAddLocation.onCreate(BTAddLocation.java:102)
这是CustomItemizedOverlay类
import java.util.ArrayList;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.widget.Toast;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
import com.readystatesoftware.mapviewballoons.BalloonItemizedOverlay;
import com.readystatesoftware.mapviewballoons.BalloonOverlayView;
public class CustomItemizedOverlay<Item extends OverlayItem> extends BalloonItemizedOverlay<CustomOverlayItem> {
private ArrayList<CustomOverlayItem> m_overlays = new ArrayList<CustomOverlayItem>();
private Context c;
public CustomItemizedOverlay(Drawable defaultMarker, MapView mapView) {
super(boundCenter(defaultMarker), mapView);
c = mapView.getContext();
}
public void addOverlay(CustomOverlayItem overlay) {
m_overlays.add(overlay);
populate();
}
@Override
protected CustomOverlayItem createItem(int i) {
return m_overlays.get(i);
}
@Override
public int size() {
return m_overlays.size();
}
@Override
protected boolean onBalloonTap(int index, CustomOverlayItem item) {
//Toast.makeText(c, "onBalloonTap for overlay index " + index,
// Toast.LENGTH_LONG).show();
return true;
}
@Override
protected BalloonOverlayView<CustomOverlayItem> createBalloonOverlayView() {
// use our custom balloon view with our custom overlay item type:
return new CustomBalloonOverlayView<CustomOverlayItem>(getMapView().getContext(), getBalloonBottomOffset());
}
}
这是CustomOverlayItem类
import com.google.android.maps.GeoPoint;
import com.google.android.maps.OverlayItem;
public class CustomOverlayItem extends OverlayItem {
protected int mIndex;
public CustomOverlayItem(GeoPoint point, String title, String snippet, int index) {
super(point, title, snippet);
mIndex = index;
}
public int getImageIndex() {
return mIndex;
}
public void setImageIndex(int index) {
this.mIndex = index;
}
}
这是CustomBalloonOverlayView类
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.google.android.maps.OverlayItem;
import com.readystatesoftware.mapviewballoons.BalloonOverlayView;
//import com.readystatesoftware.mapviewballoons.R;
public class CustomBalloonOverlayView<Item extends OverlayItem> extends BalloonOverlayView<CustomOverlayItem> {
private TextView title;
private TextView snippet;
private ImageView image;
public static int[] resId = { R.drawable.unknown_icon_white,
R.drawable.desktop_icon_white, R.drawable.desktop_icon_white,
R.drawable.desktop_icon_white, R.drawable.laptop_icon_white,
R.drawable.desktop_icon_white, R.drawable.desktop_icon_white,
R.drawable.desktop_icon_white, R.drawable.phone_icon_white,
R.drawable.phone_icon_white, R.drawable.phone_icon_white,
R.drawable.phone_icon_white, R.drawable.phone_icon_white,
R.drawable.phone_icon_white, R.drawable.headphones_icon_white,
R.drawable.headset_icon_white, R.drawable.headphones_icon_white,
R.drawable.mic_icon_white, R.drawable.speaker_icon_white,
R.drawable.headphones_icon_white, R.drawable.speaker_icon_white,
R.drawable.speaker_icon_white, R.drawable.speaker_icon_white,
R.drawable.speaker_icon_white, R.drawable.video_icon_white,
R.drawable.video_icon_white, R.drawable.video_icon_white,
R.drawable.video_icon_white, R.drawable.speaker_icon_white,
R.drawable.video_icon_white, R.drawable.gamepad_icon_white,
R.drawable.wearable_icon_white, R.drawable.wearable_icon_white,
R.drawable.wearable_icon_white, R.drawable.wearable_icon_white,
R.drawable.wearable_icon_white, R.drawable.wearable_icon_white,
R.drawable.gamepad_icon_white, R.drawable.gamepad_icon_white,
R.drawable.gamepad_icon_white, R.drawable.gamepad_icon_white,
R.drawable.gamepad_icon_white, R.drawable.gamepad_icon_white,
R.drawable.health_icon_white, R.drawable.health_icon_white,
R.drawable.health_icon_white, R.drawable.health_icon_white,
R.drawable.health_icon_white, R.drawable.health_icon_white,
R.drawable.health_icon_white, R.drawable.health_icon_white, };
public CustomBalloonOverlayView(Context context, int balloonBottomOffset) {
super(context, balloonBottomOffset);
}
@Override
protected void setupView(Context context, final ViewGroup parent) {
// inflate our custom layout into parent
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.baloon_overlay_built, parent);
// setup our fields
title = (TextView) v.findViewById(R.id.balloon_item_title);
snippet = (TextView) v.findViewById(R.id.balloon_item_snippet);
image = (ImageView) v.findViewById(R.id.balloon_item_image);
}
@Override
protected void setBalloonData(CustomOverlayItem item, ViewGroup parent) {
// map our custom item data to fields
title.setText(item.getTitle());
snippet.setText(item.getSnippet());
image.setImageResource(resId[item.getImageIndex()]);
}
private class FetchImageTask extends AsyncTask<String, Integer, Bitmap> {
@Override
protected Bitmap doInBackground(String... arg0) {
Bitmap b = null;
try {
b = BitmapFactory.decodeStream((InputStream) new URL(arg0[0]).getContent());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return b;
}
}
}
答案 0 :(得分:2)