2012-07-19 5 views
0

Je développe et application Android dans laquelle je dois utiliser google map api. Je dois afficher des informations en baloon sur le marqueur à un endroit spécifique (par la latitude et la longitude). J'ai obtenu la latitude et la longitude avec succès. Pour les superpositions pour montrer baloon j'utilise CustomItemizedOverlay mais j'obtiens l'erreur NoClassDefFoundError.NoClassDefFoundError

C'est l'image que je veux mettre en œuvre enter image description here

Ci-dessous est le code de classe nommée 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); 

Je reçois une erreur à la troisième ligne. L'erreur est

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) 

Voici classe 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()); 
} 

}

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

} 

est ici classe 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; 
     } 
    } 

} 

Répondre