4

我正在编写一个应用程序,其中我使用Google Maps Android API v2mapviewballoons库,所以我在我的 android 项目中使用了两个库:

> android mapviewballoons
> google-play-services_lib

我已经获得了 SHA1 指纹并且还创建了一个 Android App Map Key,Android 应用程序的密钥(带有证书)

但是每当我运行我的应用程序时,我都会收到不幸的应用程序已停止

Error: 
java.lang.NoClassDefFoundError:   com.era.restaurant.versionoct.map.LocationActivity

日志猫:

  04-24 10:52:51.592: D/dalvikvm(1053): GC_FOR_ALLOC freed 53K, 7% free 2421K/2600K, paused 35ms, total 38ms
04-24 10:52:51.592: I/dalvikvm-heap(1053): Grow heap (frag case) to 3.069MB for 614416-byte allocation
04-24 10:52:51.651: D/dalvikvm(1053): GC_FOR_ALLOC freed <1K, 6% free 3020K/3204K, paused 48ms, total 48ms
04-24 10:52:51.691: D/dalvikvm(1053): GC_CONCURRENT freed <1K, 6% free 3020K/3204K, paused 5ms+10ms, total 48ms
04-24 10:52:51.861: D/gralloc_goldfish(1053): Emulator without GPU emulation detected.
04-24 10:52:54.811: W/dalvikvm(1053): Unable to resolve superclass of Lcom/era/restaurant/versionoct/map/LocationActivity; (973)
04-24 10:52:54.811: W/dalvikvm(1053): Link of class 'Lcom/era/restaurant/versionoct/map/LocationActivity;' failed
04-24 10:52:54.811: E/dalvikvm(1053): Could not find class 'com.era.restaurant.versionoct.map.LocationActivity', referenced from method com.era.restaurant.versionoct.TabsActivity.setTabs
04-24 10:52:54.811: W/dalvikvm(1053): VFY: unable to resolve const-class 546 (Lcom/era/restaurant/versionoct/map/LocationActivity;) in Lcom/era/restaurant/versionoct/TabsActivity;
04-24 10:52:54.811: D/dalvikvm(1053): VFY: replacing opcode 0x1c at 0x0019
04-24 10:52:55.631: D/dalvikvm(1053): GC_FOR_ALLOC freed 67K, 6% free 3206K/3404K, paused 101ms, total 136ms
04-24 10:52:55.661: I/dalvikvm-heap(1053): Grow heap (frag case) to 3.856MB for 635812-byte allocation
04-24 10:52:55.762: D/dalvikvm(1053): GC_CONCURRENT freed 8K, 6% free 3819K/4028K, paused 5ms+5ms, total 107ms
04-24 10:52:56.091: D/AndroidRuntime(1053): Shutting down VM
04-24 10:52:56.111: W/dalvikvm(1053): threadid=1: thread exiting with uncaught exception (group=0x40a71930)
04-24 10:52:56.191: E/AndroidRuntime(1053): FATAL EXCEPTION: main
04-24 10:52:56.191: E/AndroidRuntime(1053): java.lang.NoClassDefFoundError: com.era.restaurant.versionoct.map.LocationActivity
04-24 10:52:56.191: E/AndroidRuntime(1053):     at com.era.restaurant.versionoct.TabsActivity.setTabs(TabsActivity.java:35)
04-24 10:52:56.191: E/AndroidRuntime(1053):     at com.era.restaurant.versionoct.TabsActivity.onCreate(TabsActivity.java:26)
04-24 10:52:56.191: E/AndroidRuntime(1053):     at android.app.Activity.performCreate(Activity.java:5104)
04-24 10:52:56.191: E/AndroidRuntime(1053):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
04-24 10:52:56.191: E/AndroidRuntime(1053):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2144)
04-24 10:52:56.191: E/AndroidRuntime(1053):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
04-24 10:52:56.191: E/AndroidRuntime(1053):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
04-24 10:52:56.191: E/AndroidRuntime(1053):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
04-24 10:52:56.191: E/AndroidRuntime(1053):     at android.os.Handler.dispatchMessage(Handler.java:99)
04-24 10:52:56.191: E/AndroidRuntime(1053):     at android.os.Looper.loop(Looper.java:137)
04-24 10:52:56.191: E/AndroidRuntime(1053):     at android.app.ActivityThread.main(ActivityThread.java:5041)
04-24 10:52:56.191: E/AndroidRuntime(1053):     at java.lang.reflect.Method.invokeNative(Native Method)
04-24 10:52:56.191: E/AndroidRuntime(1053):     at java.lang.reflect.Method.invoke(Method.java:511)
04-24 10:52:56.191: E/AndroidRuntime(1053):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
04-24 10:52:56.191: E/AndroidRuntime(1053):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
04-24 10:52:56.191: E/AndroidRuntime(1053):     at dalvik.system.NativeStart.main(Native Method)

活动位置.xml:

  <RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical"
   >

 <include
    android:id="@+id/header"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    layout="@layout/header_location" 
    />

<com.readystatesoftware.maps.TapControlledMapView
    android:id="@+id/viewmap"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:layout_alignParentBottom="true"
    android:layout_below="@+id/rg_views"
    android:clickable="true" />

   <RadioGroup
    android:id="@+id/rg_views"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/header"
    android:background="@color/tabMedium"
    android:gravity="center_horizontal"
    android:orientation="horizontal" >

    <RadioButton
        android:id="@+id/rb_satellite"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/header"
        android:layout_marginRight="16dp"
        android:text="@string/str_rb_satellite" />

    <RadioButton
        android:id="@+id/rb_normal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignTop="@+id/viewmap"
        android:layout_marginLeft="14dp"
        android:checked="true"
        android:text="@string/str_rb_normal" />
    </RadioGroup>

    </RelativeLayout>

AndroidManifest.xml(仅显示与地图相关的内容)::

        <uses-permission  
    android:name="com.era.restaurant.versionoct.maps.permission.MAPS_RECEIVE"
    >
    </uses-permission>

<permission  
    android:name="com.era.restaurant.versionoct.maps.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission 
    android:name="com.google.android.providers.gsf.permission.READ_GSERVICES">
</uses-permission>

<uses-feature 
    android:glEsVersion="0x00020000" android:required="true">
   </uses-feature>


<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" 
    android:allowBackup="false">

  <activity 
        android:name="com.era.restaurant.versionoct.map.LocationActivity"
        android:label="@string/app_name">
   </activity>

 <meta-data
   android:name="com.era.restaurant.versionoct.map.v2.API_KEY"
   android:value="myAPIkey"/>

位置活动.java:

   public class LocationActivity extends MapActivity {
public GeoPoint point;
TapControlledMapView mapView=null; // use the custom TapControlledMapView
List<Overlay> mapOverlays;
Drawable drawable;
SimpleItemizedOverlay itemizedOverlay;

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

    mapView = (TapControlledMapView) findViewById(R.id.viewmap);
    mapView.setBuiltInZoomControls(true);
    mapView.setSatellite(false);
   // Getting reference to rg_views of the layout activity_main
    RadioGroup rgViews = (RadioGroup) findViewById(R.id.rg_views);

    // Defining Checked Change Listener for the RadioGroup
    OnCheckedChangeListener checkedChangeListener = new OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {

            // Getting Reference to map_view of the layout activity_main

            // Currently checked is rb_map
            if(checkedId==R.id.rb_normal){
                mapView.setSatellite(false);
            }

            // Currently checked is rb_satellite
            if(checkedId==R.id.rb_satellite){
                mapView.setSatellite(true);
            }
        }
    };

    // Setting Checked ChangeListener
    rgViews.setOnCheckedChangeListener(checkedChangeListener);


    // dismiss balloon upon single tap of MapView (iOS behavior) 
    mapView.setOnSingleTapListener(new OnSingleTapListener() {      

        public boolean onSingleTap(MotionEvent e) {
            itemizedOverlay.hideAllBalloons();
            return true;

        }
    });

    mapOverlays = mapView.getOverlays();        
    drawable = getResources().getDrawable(R.drawable.map_button);
    itemizedOverlay = new SimpleItemizedOverlay(drawable, mapView);         
    itemizedOverlay.setShowClose(false);
    itemizedOverlay.setShowDisclosure(true);
    itemizedOverlay.setSnapToCenter(true);
    new DownloadWebPageTask().execute();

    }

class DownloadWebPageTask extends AsyncTask<String, Void, String> {
        @Override
        protected String doInBackground(String... urls) {

            HttpClient client = new DefaultHttpClient();
            // Perform a GET request for a JSON list
            HttpUriRequest request = new HttpGet("http://XXXX.xxx/locations.json");

            // Get the response that sends back
            HttpResponse response = null;
            try {
                response = client.execute(request);
            } catch (ClientProtocolException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            // Convert this response into a readable string
            String jsonString = null;
            try {
                jsonString = StreamUtils.convertToString(response.getEntity().getContent());
            } catch (IllegalStateException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            // Create a JSON object that we can use from the String
            JSONObject json = null;
            try {
                json = new JSONObject(jsonString);
            } catch (JSONException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }


            try{
                JSONArray jsonArray = json.getJSONArray("maps");
                Log.e("log_tag", "Opening JSON Array ");
                for(int i=0;i < jsonArray.length();i++){                      
                    JSONObject jsonObject = jsonArray.getJSONObject(i);
                    String latitude =  jsonObject.getString("latitude");
                    String longitude =  jsonObject.getString("longitude");
                    String title =  jsonObject.getString("title");
                    String country = jsonObject.getString("location");
                    double lat = Double.parseDouble(latitude);
                    double lng = Double.parseDouble(longitude);
                    Log.e("log_tag", "ADDING GEOPOINT"+title); 
                    point = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
                    OverlayItem overlayItem = new OverlayItem(point, title, country);
                    itemizedOverlay.addOverlay(overlayItem);
               }
           }catch(JSONException e)        {
               Log.e("log_tag", "Error parsing data "+e.toString());
           } 


           return jsonString;
       }

        @SuppressWarnings("unused")
        @Override
        protected void onPostExecute(String result) {
                    itemizedOverlay.populateNow(); 

           mapOverlays.add(itemizedOverlay);
           Object savedInstanceState = null;
              }




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

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

 }

SimpleItemizedOverlay.java:

 public class SimpleItemizedOverlay extends BalloonItemizedOverlay<OverlayItem> {

private ArrayList<OverlayItem> m_overlays = new ArrayList<OverlayItem>();
public SimpleItemizedOverlay(Drawable defaultMarker, MapView mapView) {
    super(boundCenter(defaultMarker), mapView);
    mapView.getContext();
}
@Override
public void draw(Canvas canvas, MapView mapView, boolean shadow)
{
    if(!shadow)
    {
        super.draw(canvas, mapView, false);
    }
}

public void addOverlay(OverlayItem overlay) {
    m_overlays.add(overlay);

}
public void populateNow()
{
    populate(); 
}

@Override
protected OverlayItem createItem(int i) {
    return m_overlays.get(i);
}

@Override
public int size() {
    return m_overlays.size();
}
4

1 回答 1

0

您收到此错误:

java.lang.NoClassDefFoundError: com.era.restaurant.versionoct.map.LocationActivity

因为您的LocationActivityextends MapActivity,一个来自 - 现在已弃用 - Maps Android API v1库的类,您的项目中缺少该类:

Unable to resolve superclass of Lcom/era/restaurant/versionoct/map/LocationActivity; (973)

此外,就像 Archie.bpgc 所说,您可以安全地从项目中删除android-mapviewballoons库,而使用新的Maps Android API v2,它具有该第三方库提供的所有功能。

于 2013-04-24T11:39:13.373 回答