Android : Getting Noclassdeffounderror on working with Google places API android

on Wednesday, August 13, 2014


I am working on a tutorial found on this link:


http://www.androidhive.info/2012/08/android-working-with-google-places-and-maps-tutorial/


I am getting the following error on clicking the button:



08-13 12:28:03.226: E/AndroidRuntime(9180): FATAL EXCEPTION: main
08-13 12:28:03.226: E/AndroidRuntime(9180): java.lang.NoClassDefFoundError: com.androidhive.googleplacesandmaps.PlacesMapActivity
08-13 12:28:03.226: E/AndroidRuntime(9180): at com.androidhive.googleplacesandmaps.MainActivity$1.onClick(MainActivity.java:110)
08-13 12:28:03.226: E/AndroidRuntime(9180): at android.view.View.performClick(View.java:2538)
08-13 12:28:03.226: E/AndroidRuntime(9180): at android.view.View$PerformClick.run(View.java:9152)
08-13 12:28:03.226: E/AndroidRuntime(9180): at android.os.Handler.handleCallback(Handler.java:587)
08-13 12:28:03.226: E/AndroidRuntime(9180): at android.os.Handler.dispatchMessage(Handler.java:92)
08-13 12:28:03.226: E/AndroidRuntime(9180): at android.os.Looper.loop(Looper.java:130)
08-13 12:28:03.226: E/AndroidRuntime(9180): at android.app.ActivityThread.main(ActivityThread.java:3689)
08-13 12:28:03.226: E/AndroidRuntime(9180): at java.lang.reflect.Method.invokeNative(Native Method)
08-13 12:28:03.226: E/AndroidRuntime(9180): at java.lang.reflect.Method.invoke(Method.java:507)
08-13 12:28:03.226: E/AndroidRuntime(9180): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:842)
08-13 12:28:03.226: E/AndroidRuntime(9180): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
08-13 12:28:03.226: E/AndroidRuntime(9180): at dalvik.system.NativeStart.main(Native Method)
08-13 12:28:03.226: E/AndroidRuntime(9180): Caused by: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
08-13 12:28:03.226: E/AndroidRuntime(9180): at dalvik.system.DexFile.defineClass(Native Method)
08-13 12:28:03.226: E/AndroidRuntime(9180): at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:207)
08-13 12:28:03.226: E/AndroidRuntime(9180): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:200)
08-13 12:28:03.226: E/AndroidRuntime(9180): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
08-13 12:28:03.226: E/AndroidRuntime(9180): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
08-13 12:28:03.226: E/AndroidRuntime(9180): ... 12 more


The placesmapactivity.java class is shown below:



package com.androidhive.googleplacesandmaps;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;

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 PlacesMapActivity extends MapActivity {
// Nearest places
PlacesList nearPlaces;

// Map view
MapView mapView;

// Map overlay items
List<Overlay> mapOverlays;

AddItemizedOverlay itemizedOverlay;

GeoPoint geoPoint;
// Map controllers
MapController mc;

double latitude;
double longitude;
OverlayItem overlayitem;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map_places);

// Getting intent data
Intent i = getIntent();

// Users current geo location
String user_latitude = i.getStringExtra("user_latitude");
String user_longitude = i.getStringExtra("user_longitude");

// Nearplaces list
nearPlaces = (PlacesList) i.getSerializableExtra("near_places");

mapView = (MapView) findViewById(R.id.mapView);
mapView.setBuiltInZoomControls(true);

mapOverlays = mapView.getOverlays();

// Geopoint to place on map
geoPoint = new GeoPoint((int) (Double.parseDouble(user_latitude) * 1E6),
(int) (Double.parseDouble(user_longitude) * 1E6));

// Drawable marker icon
Drawable drawable_user = this.getResources()
.getDrawable(R.drawable.mark_red);

itemizedOverlay = new AddItemizedOverlay(drawable_user, this);

// Map overlay item
overlayitem = new OverlayItem(geoPoint, "Your Location",
"That is you!");

itemizedOverlay.addOverlay(overlayitem);

mapOverlays.add(itemizedOverlay);
itemizedOverlay.populateNow();

// Drawable marker icon
Drawable drawable = this.getResources()
.getDrawable(R.drawable.mark_blue);

itemizedOverlay = new AddItemizedOverlay(drawable, this);

mc = mapView.getController();

// These values are used to get map boundary area
// The area where you can see all the markers on screen
int minLat = Integer.MAX_VALUE;
int minLong = Integer.MAX_VALUE;
int maxLat = Integer.MIN_VALUE;
int maxLong = Integer.MIN_VALUE;

// check for null in case it is null
if (nearPlaces.results != null) {
// loop through all the places
for (Place place : nearPlaces.results) {
latitude = place.geometry.location.lat; // latitude
longitude = place.geometry.location.lng; // longitude

// Geopoint to place on map
geoPoint = new GeoPoint((int) (latitude * 1E6),
(int) (longitude * 1E6));

// Map overlay item
overlayitem = new OverlayItem(geoPoint, place.name,
place.vicinity);

itemizedOverlay.addOverlay(overlayitem);


// calculating map boundary area
minLat = (int) Math.min( geoPoint.getLatitudeE6(), minLat );
minLong = (int) Math.min( geoPoint.getLongitudeE6(), minLong);
maxLat = (int) Math.max( geoPoint.getLatitudeE6(), maxLat );
maxLong = (int) Math.max( geoPoint.getLongitudeE6(), maxLong );
}
mapOverlays.add(itemizedOverlay);

// showing all overlay items
itemizedOverlay.populateNow();
}

// Adjusting the zoom level so that you can see all the markers on map
mapView.getController().zoomToSpan(Math.abs( minLat - maxLat ), Math.abs( minLong - maxLong ));

// Showing the center of the map
mc.animateTo(new GeoPoint((maxLat + minLat)/2, (maxLong + minLong)/2 ));
mapView.postInvalidate();

}

@Override
protected boolean isRouteDisplayed() {
// TODO Auto-generated method stub
return false;
}


The button click code is shown below:

btnShowOnMap.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
Intent i = new Intent(MainActivity.this,
PlacesMapActivity.class);
// Sending user current geo location
i.putExtra("user_latitude", Double.toString(gps.getLatitude()));
i.putExtra("user_longitude", Double.toString(gps.getLongitude()));

// passing near places to map activity
i.putExtra("near_places", nearPlaces);
// staring activity
startActivity(i);
}
});


}

0 comments:

Post a Comment