0

就在我点击按钮时,我想根据给定的 lan 和 lat 点显示 gogle 地图,但是当我想点击它时,我得到 java.lang.NoClassDefFoundError: com/androidhive/googleplacesandmaps/PlacesMapActivity 当我在我的设备中访问谷歌地图时

如何解决这个问题?

MainActivity.java

 btnShowOnMap.setOnClickListener(new View.OnClickListener() {
 @Override
 public void onClick(View arg0) {
 Intent i = new Intent(getApplicationContext(),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);
 }
 });

地点地图活动

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() {
        return false;
    }

}

显现

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.androidhive.googleplacesandmaps"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="17" />
    <!-- Internet Permissions -->
    <uses-permission android:name="android.permission.INTERNET" />

    <!-- Network State Permissions -->
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

    <!-- Access Location -->
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"
        android:allowBackup="true" >

        <!-- Add Google Map Library -->
        <uses-library
            android:name="com.google.android.maps"
            android:required="true" />

        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <!-- SinglePlaceActivity -->
        <activity
            android:name=".SinglePlaceActivity"
            android:label="Place Details" >
        </activity>

        <!-- PlacesMapActivity -->
        <activity
            android:name="PlacesMapActivity"
            android:label="Near Places Map View" >
            <intent-filter>
                <meta-data
                    android:name="com.google.android.maps.v2.API_KEY"
                    android:value="AIzaSyChOUhcZd3M2WiPhfXE8apM3LTOTjrq30M" />
            </intent-filter>
        </activity>
    </application>

</manifest>

日志猫

07-02 23:01:14.100: E/AndroidRuntime(9182):     at com.androidhive.googleplacesandmaps.MainActivity$1.onClick(MainActivity.java:110)
07-02 23:01:14.100: E/AndroidRuntime(9182):     at android.view.View.performClick(View.java:3528)
07-02 23:01:14.100: E/AndroidRuntime(9182):     at android.view.View$PerformClick.run(View.java:14235)
07-02 23:01:14.100: E/AndroidRuntime(9182):     at android.os.Handler.handleCallback(Handler.java:605)
07-02 23:01:14.100: E/AndroidRuntime(9182):     at android.os.Handler.dispatchMessage(Handler.java:92)
07-02 23:01:14.100: E/AndroidRuntime(9182):     at android.os.Looper.loop(Looper.java:137)
07-02 23:01:14.100: E/AndroidRuntime(9182):     at android.app.ActivityThread.main(ActivityThread.java:4424)
07-02 23:01:14.100: E/AndroidRuntime(9182):     at java.lang.reflect.Method.invokeNative(Native Method)
07-02 23:01:14.100: E/AndroidRuntime(9182):     at java.lang.reflect.Method.invoke(Method.java:511)
07-02 23:01:14.100: E/AndroidRuntime(9182):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:817)
07-02 23:01:14.100: E/AndroidRuntime(9182):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
07-02 23:01:14.100: E/AndroidRuntime(9182):     at dalvik.system.NativeStart.main(Native Method)
07-02 23:01:14.100: E/AndroidRuntime(9182): Caused by: java.lang.IllegalAccessError: Class ref in pre-verified class resolved to unexpected implementation
07-02 23:01:14.100: E/AndroidRuntime(9182):     at dalvik.system.DexFile.defineClass(Native Method)
07-02 23:01:14.100: E/AndroidRuntime(9182):     at dalvik.system.DexFile.loadClassBinaryName(DexFile.java:195)
07-02 23:01:14.100: E/AndroidRuntime(9182):     at dalvik.system.DexPathList.findClass(DexPathList.java:315)
07-02 23:01:14.100: E/AndroidRuntime(9182):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:58)
07-02 23:01:14.100: E/AndroidRuntime(9182):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-02 23:01:14.100: E/AndroidRuntime(9182):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-02 23:01:14.100: E/AndroidRuntime(9182):     ... 12 more
4

2 回答 2

0

我感觉在 android manifest.xml 中应该是这样的...

<activity
        android:name=".PlacesMapActivity"
        android:label="Near Places Map View" >
于 2013-07-04T14:53:24.050 回答
0

阅读你的清单,看看所有活动在它的名字之前是如何有一个点的

 <activity
        android:name=".SinglePlaceActivity"
        android:label="Place Details" >
    </activity>

但是您没有在 PlacesMapActivity 之前指出一点

 <activity
        android:name="PlacesMapActivity"
        android:label="Near Places Map View" >

所以它不会吃午饭,就这样吧:

 <activity
        android:name=".PlacesMapActivity"
        android:label="Near Places Map View" >
于 2013-07-04T15:16:14.140 回答