2012-07-19 131 views
0

我正在開發和Android應用程序,我必須使用谷歌地圖API。我必須在特定位置(按經度和緯度)在標記上顯示氣球信息。我成功地獲得了經緯度。對於覆蓋顯示baloon我使用CustomItemizedOverlay但我得到NoClassDefFoundError錯誤。NoClassDefFoundError

這是什麼圖片我想實現 enter image description here

下面是一個名爲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; 
     } 
    } 

} 

回答