2013-05-09 64 views
1

我想在我的Android設備上構建谷歌地圖應用程序。它工作正常,但最近它一直在給出錯誤。不幸的是myAndroidapp已經停止。應用程序包括地圖

該應用程序給出錯誤致命錯誤:主。我發佈代碼和日誌錯誤文件。請幫助我解決這個問題。 我的android設備是否有任何問題,因爲相同的代碼對我來說工作正常。 Android清單: -

<?xml version="1.0" encoding="utf-8"?> 
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="com.example.googlemaps" 
    android:versionCode="1" 
    android:versionName="1.0" > 
     <uses-sdk android:minSdkVersion="8" 
    android:targetSdkVersion="17"/> 
    <application 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" > 

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

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

      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
    <meta-data 
     android:name="com.google.android.maps.v2.API_KEY" 
     android:value="AIzaSyBX1XULUbZ8KEpvy60JsDKxmYWtVuIs2X0"/> 
    </application> 
    <uses-feature 
    android:glEsVersion="0x00020000" 
    android:required="true"/> 
    <permission android:name="com.example.googlemaps.permission.MAPS_RECEIVE"     android:protectionLevel="signature"/> 
    <uses-permission android:name="com.example.googlemaps.permission.MAPS_RECEIVE"/> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
    <uses-permission  android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/> 
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
     <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 



     </manifest> 

MapActivity.java

package com.example.googlemaps; 
import android.app.Dialog; 
import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 

import com.google.android.gms.common.ConnectionResult; 
import com.google.android.gms.common.GooglePlayServicesUtil; 
import com.google.android.gms.maps.CameraUpdateFactory; 
import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.model.BitmapDescriptorFactory; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.MarkerOptions; 


public class MapsActivity extends FragmentActivity { 
    //Intent in = getIntent(); 
    //String latitude = in.getStringExtra("latitude"); 
    //String longitude = in.getStringExtra("longitude"); 


    GoogleMap googleMap; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     // Getting Google Play availability status 
     int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext()); 

     // Showing status 
     if(status!=ConnectionResult.SUCCESS){ // Google Play Services are not available 

      int requestCode = 10; 
      Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode); 
      dialog.show(); 

     }else { // Google Play Services are available 


      // Double latitude1=Double.parseDouble(latitude); 
      // Double longitude1=Double.parseDouble(longitude); 

      // Getting reference to the SupportMapFragment of activity_main.xml 
      SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map); 

      // Getting GoogleMap object from the fragment 
      googleMap = fm.getMap(); 

      // Enabling MyLocation Layer of Google Map 
      googleMap.setMyLocationEnabled(true); 

      googleMap.addMarker(new MarkerOptions().position(new LatLng(28.62293,77.36403)).title("SaveMe").snippet("Place of Interest").icon(BitmapDescriptorFactory.fromResource(R.drawable.marker))); 

       //System.out.println("Marker added"); 


      // Showing the current location in Google Map 
      googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(28.62293, 77.36403))); 

      // Zoom in the Google Map 
      googleMap.animateCamera(CameraUpdateFactory.zoomTo(14)); 

      // Setting latitude and longitude in the TextView tv_location 
     } 
    } 




} 

mail.xml: -

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <fragment 
     android:name="com.google.android.gms.maps.SupportMapFragment" 

     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
</LinearLayout> 

錯誤: -

05-09 11:28:37.156: W/dalvikvm(27963): threadid=1: thread exiting with uncaught exception (group=0x40aa1210) 
05-09 11:28:37.156: E/AndroidRuntime(27963): FATAL EXCEPTION: main 
05-09 11:28:37.156: E/AndroidRuntime(27963): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable 
05-09 11:28:37.156: E/AndroidRuntime(27963): at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at android.view.LayoutInflater.rInflate(LayoutInflater.java:739) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at android.view.LayoutInflater.inflate(LayoutInflater.java:489) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at android.view.LayoutInflater.inflate(LayoutInflater.java:396) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at android.view.LayoutInflater.inflate(LayoutInflater.java:352) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:255) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at android.app.Activity.setContentView(Activity.java:1835) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at com.example.googlemaps.MapsActivity.onCreate(MapsActivity.java:28) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at android.app.Activity.performCreate(Activity.java:4465) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at android.app.ActivityThread.access$600(ActivityThread.java:127) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at android.os.Handler.dispatchMessage(Handler.java:99) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at android.os.Looper.loop(Looper.java:137) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at android.app.ActivityThread.main(ActivityThread.java:4441) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at java.lang.reflect.Method.invokeNative(Native Method) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at java.lang.reflect.Method.invoke(Method.java:511) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590) 
05-09 11:28:37.156: E/AndroidRuntime(27963): at dalvik.system.NativeStart.main(Native Method) 
+1

您是否添加了支持庫?有沒有在你的地圖項目中引用google play服務庫? – Raghunandan 2013-05-09 06:35:52

+0

是的,我已經引用它.. – user2365029 2013-05-09 09:45:26

+0

你添加了支持庫,因爲你正在使用支持片段? – Raghunandan 2013-05-09 09:46:16

回答

0

的代碼工作假設你已經提到的支持庫和谷歌正常播放服務。它顯示了扇區32的塊A.查看this瞭解如何在應用程序中包含地圖。

+0

我再次重新安裝谷歌播放服務,但仍然存在錯誤。包括jar文件會出現錯誤.....? – user2365029 2013-05-09 10:12:35

+0

我們必須包含多少個jar文件?以及如何..請指定它.. ?? O認爲我在引用jar文件時遇到了一些問題.. – user2365029 2013-05-09 10:26:34

+0

您必須僅引用一個jar,即android-support-v4,google-service-play必須作爲庫項目引用。 – 2013-05-10 03:41:55

0

你忘了提到在片段佈局類,而不是你正在使用的名稱

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 

    <fragment 
     class="com.google.android.gms.maps.SupportMapFragment" 
     android:id="@+id/map" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 
</LinearLayout> 
+0

我已更名爲類..但仍然錯誤是相同的 – user2365029 2013-05-09 09:46:13

+0

如何在項目中添加庫 – 2013-05-09 13:41:32

+0

android-sdk-macosx/extras/google/google_play_services/libproject/google-play-services_lib – 2013-05-09 14:01:16