4

我寫在裏面我是用谷歌地圖API的Android V2mapviewballoons庫沿着一個應用程序,所以我有我使用兩個庫在我的Android項目:錯誤充氣類com.readystatesoftware.maps.TapControlledMapView

> android mapviewballoons 
> google-play-services_lib 

獲得SHA1指紋又創造了一個Android應用程序圖例,重點for Android應用程序(帶證書)

但每當我跑我的應用程序,我得到不幸的是應用程序已經停止

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

logcat的:

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) 

activity_location.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(僅顯示對地圖相關NGS)::

 <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"/> 

LocationActivity.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(); 
} 
+2

您實際上不需要'com.readystatesoftware.maps'庫了,如果您正在使用** Map V2 ** – 2013-04-24 11:06:37

+0

是的,我正在使用Map V2,那麼應該用什麼來代替com.readystatesoftware .maps.TapControlledMapView @ Archie.bpgc – 2013-04-24 11:09:01

+1

@ChulbulPandey該庫將在單擊標記時顯示信息窗口。您可以輕鬆地使用[此處]的回電(https://developers.google.com/maps/documentation/android/reference/com/google/android/gms/maps/GoogleMap)。通過[文檔](https://developers.google.com/maps/documentation/android/)也很重要 – 2013-04-24 11:20:42

回答

0

您收到此錯誤:

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

因爲你LocationActivity延伸MapActivity,從一類 - 現在已經過時 - Android的地圖API V1庫,該庫中缺少項目:

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

此外,像Archie.bpgc說,你可以安全地從您的項目中刪除android-mapviewballoons庫,而改爲而不是使用新的Maps Android API v2,它具有該第三方庫提供的所有功能。