给出错误:java.lang.NoClassDefFoundError:com.google.android.maps.MapView for offline map android project

时间:2014-10-07 11:04:56

标签: java android map

我是离线地图的新手,我正在尝试为我的Android项目显示离线地图。我有这段代码,但在运行时出现此错误:java.lang.NoClassDefFoundError: com.google.android.maps.MapView 现在我想知道什么是问题? 在我的代码之前,我必须告诉我在我的项目中添加了我的libs文件夹所需的jar文件。我不确定下面的代码是否正确。 Manifet文件:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="android.gps.offline"
    android:versionCode="1"
    android:versionName="1.0" >

     <uses-sdk android:minSdkVersion="11" />
     <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
     <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
     <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
     <uses-permission android:name="android.permission.INTERNET"/>
     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

     <uses-library android:required="true" android:name="com.google.android.maps" />
     <uses-library android:name="com.google.android.maps.MapView" />
     <uses-library android:name="com.google.android.maps" />      

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name" >
        <activity
            android:label="@string/app_name"
            android:name=".MainActivity" >
            <intent-filter >
                <action android:name="android.intent.action.MAIN" />

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

</manifest>

main.xml档案:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:text="hello gps"
        tools:context=".MainActivity" />

    <org.osmdroid.views.MapView
        android:id="@+id/mapview"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:clickable="true"/>

</RelativeLayout>

档案MainActivity.java

import org.osmdroid.DefaultResourceProxyImpl;
import org.osmdroid.ResourceProxy;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;

public class MainActivity extends Activity {

     MyItemizedOverlay myItemizedOverlay = null;

        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            MapView mapView = (MapView)findViewById(R.id.mapview);
            mapView.setBuiltInZoomControls(true);

            Drawable marker=getResources().getDrawable(android.R.drawable.star_big_on);
            int markerWidth = marker.getIntrinsicWidth();
            int markerHeight = marker.getIntrinsicHeight();
            marker.setBounds(0, markerHeight, markerWidth, 0);

            ResourceProxy resourceProxy = new DefaultResourceProxyImpl(getApplicationContext());

            myItemizedOverlay = new MyItemizedOverlay(marker, resourceProxy);
            mapView.getOverlays().add(myItemizedOverlay);

            GeoPoint myPoint1 = new GeoPoint(0*1000000, 0*1000000);
            myItemizedOverlay.addItem(myPoint1, "myPoint1", "myPoint1");
            GeoPoint myPoint2 = new GeoPoint(50*1000000, 50*1000000);
            myItemizedOverlay.addItem(myPoint2, "myPoint2", "myPoint2");

        }

    }

档案MyItemizedOverlay.java

import java.util.ArrayList;

import org.osmdroid.ResourceProxy;

import android.graphics.Point;
import android.graphics.drawable.Drawable;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;


    public class MyItemizedOverlay extends ItemizedOverlay<OverlayItem> 
    {
        private ArrayList<OverlayItem> overlayItemList = new ArrayList<OverlayItem>();
        public MyItemizedOverlay(Drawable pDefaultMarker,
                   ResourceProxy pResourceProxy) {
                  super(pDefaultMarker);
                  // TODO Auto-generated constructor stub
                 }

         public void addItem(GeoPoint p, String title, String snippet){
              OverlayItem newItem = new OverlayItem(p, snippet, title);
              overlayItemList.add(newItem);
              populate();
             }
         @Override
        public boolean onSnapToItem(int x, int y, Point snapPoint,
                MapView mapView) {
            // TODO Auto-generated method stub
        //  return super.onSnapToItem(x, y, snapPoint, mapView);
             return false;
         }
        @Override
        protected OverlayItem createItem(int i) {
            // TODO Auto-generated method stub
            return overlayItemList.get(i);
        }

        @Override
        public int size() {
            // TODO Auto-generated method stub
            return overlayItemList.size();
        }

    }

我还会在下面选择一张图片: picture of java build path

0 个答案:

没有答案