2014-03-25 31 views
0

我的代碼/AndroidRuntime致命異常:主要的11月3日至25日:50:16.455

private static final LatLng AMSTERDAM = new LatLng(52.37518, 4.895439); 
private static final LatLng PARIS = new LatLng(48.856132, 2.352448); 
private static final LatLng FRANKFURT = new LatLng(50.111772, 8.682632); 
private GoogleMap map; 
private LatLngBounds latlngBounds; 
private Button bNavigation; 
private Polyline newPolyline; 
private boolean isTravelingToParis = false; 
private int width, height; 


@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_navigation); 

    getSreenDimanstions(); 

    map = ((SupportMapFragment) getSupportFragmentManager() 
      .findFragmentById(R.id.map)).getMap(); 

    bNavigation = (Button) findViewById(R.id.bNavigation); 
    bNavigation.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      if (!isTravelingToParis) 
      { 
       isTravelingToParis = true; 
       findDirections(AMSTERDAM.latitude, AMSTERDAM.longitude,PARIS.latitude, PARIS.longitude, GMapV2Direction.MODE_DRIVING); 
      } 
      else 
      { 
       isTravelingToParis = false; 
       findDirections(AMSTERDAM.latitude, AMSTERDAM.longitude, FRANKFURT.latitude, FRANKFURT.longitude, GMapV2Direction.MODE_DRIVING); 
      } 
     } 
    }); 
} 

@Override 
protected void onResume() { 

    super.onResume(); 
    latlngBounds = createLatLngBoundsObject(AMSTERDAM, PARIS); 
    map.moveCamera(CameraUpdateFactory.newLatLngBounds(latlngBounds, width, height, 150)); 

} 

public void handleGetDirectionsResult(ArrayList<LatLng> directionPoints) { 
    PolylineOptions rectLine = new PolylineOptions().width(5).color(Color.RED); 

    for(int i = 0 ; i < directionPoints.size() ; i++) 
    {   
     rectLine.add(directionPoints.get(i)); 
    } 
    if (newPolyline != null) 
    { 
     newPolyline.remove(); 
    } 
    newPolyline = map.addPolyline(rectLine); 
    if (isTravelingToParis) 
    { 
     latlngBounds = createLatLngBoundsObject(AMSTERDAM, PARIS); 
     map.animateCamera(CameraUpdateFactory.newLatLngBounds(latlngBounds, width, height, 150)); 
    } 
    else 
    { 
     latlngBounds = createLatLngBoundsObject(AMSTERDAM, FRANKFURT); 
     map.animateCamera(CameraUpdateFactory.newLatLngBounds(latlngBounds, width, height, 150)); 
    } 

} 

private void getSreenDimanstions() 
{ 
    Display display = getWindowManager().getDefaultDisplay(); 
    width = display.getWidth(); 
    height = display.getHeight(); 
} 

private LatLngBounds createLatLngBoundsObject(LatLng firstLocation, LatLng secondLocation) 
{ 
    if (firstLocation != null && secondLocation != null) 
    { 
     LatLngBounds.Builder builder = new LatLngBounds.Builder();  
     builder.include(firstLocation).include(secondLocation); 

     return builder.build(); 
    } 
    return null; 
} 

public void findDirections(double fromPositionDoubleLat, double fromPositionDoubleLong, double toPositionDoubleLat, double toPositionDoubleLong, String mode) 
{ 
    Map<String, String> map = new HashMap<String, String>(); 
    map.put(GetDirectionsAsyncTask.USER_CURRENT_LAT, String.valueOf(fromPositionDoubleLat)); 
    map.put(GetDirectionsAsyncTask.USER_CURRENT_LONG, String.valueOf(fromPositionDoubleLong)); 
    map.put(GetDirectionsAsyncTask.DESTINATION_LAT, String.valueOf(toPositionDoubleLat)); 
    map.put(GetDirectionsAsyncTask.DESTINATION_LONG, String.valueOf(toPositionDoubleLong)); 
    map.put(GetDirectionsAsyncTask.DIRECTIONS_MODE, mode); 

    GetDirectionsAsyncTask asyncTask = new GetDirectionsAsyncTask(this); 
    asyncTask.execute(map); 
} 
} 

MyLogCat

03-25 11:50:16.455: E/AndroidRuntime(11838): FATAL EXCEPTION: main 
03-25 11:50:16.455: E/AndroidRuntime(11838): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.emildesign.navigationapplication/com.emildesign.navigationapplication.NavigationActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment 
03-25 11:50:16.455: E/AndroidRuntime(11838): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2249) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2299) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at android.app.ActivityThread.access$700(ActivityThread.java:154) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1284) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at android.os.Handler.dispatchMessage(Handler.java:99) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at android.os.Looper.loop(Looper.java:137) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at android.app.ActivityThread.main(ActivityThread.java:5306) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at java.lang.reflect.Method.invokeNative(Native Method) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at java.lang.reflect.Method.invoke(Method.java:511) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at dalvik.system.NativeStart.main(Native Method) 
03-25 11:50:16.455: E/AndroidRuntime(11838): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment 
03-25 11:50:16.455: E/AndroidRuntime(11838): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:710) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at android.view.LayoutInflater.rInflate(LayoutInflater.java:752) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at android.view.LayoutInflater.inflate(LayoutInflater.java:495) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at android.view.LayoutInflater.inflate(LayoutInflater.java:397) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at android.view.LayoutInflater.inflate(LayoutInflater.java:353) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:342) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at android.app.Activity.setContentView(Activity.java:1928) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at com.emildesign.navigationapplication.NavigationActivity.onCreate(NavigationActivity.java:40) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at android.app.Activity.performCreate(Activity.java:5255) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1097) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2213) 
03-25 11:50:16.455: E/AndroidRuntime(11838): ... 11 more 
03-25 11:50:16.455: E/AndroidRuntime(11838): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4132500 but found 0. You must have the following declaration within the <application> element:  <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> 
03-25 11:50:16.455: E/AndroidRuntime(11838): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at com.google.android.gms.maps.internal.q.v(Unknown Source) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at com.google.android.gms.maps.internal.q.u(Unknown Source) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at com.google.android.gms.maps.MapFragment$b.eb(Unknown Source) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at com.google.android.gms.maps.MapFragment$b.a(Unknown Source) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at com.google.android.gms.dynamic.a.a(Unknown Source) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at com.google.android.gms.dynamic.a.onInflate(Unknown Source) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at android.app.Activity.onCreateView(Activity.java:4857) 
03-25 11:50:16.455: E/AndroidRuntime(11838): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:686) 
03-25 11:50:16.455: E/AndroidRuntime(11838): ... 21 more 
+0

你有AndroidManifest.xml中的',在最後一個「Caused by」子句中指定堆棧跟蹤? –

+0

張貼您的'Manifest' xml。 –

回答

1

在您貼出LogCat,其明確表示,

You must have the following declaration within the <application> element:  <meta-data android:name="com.google.android.gms.version" android:value="@integer/google_play_services_version" /> 

可能是你原諒請勿將Google Play服務版本添加到您的應用的Manifest。現在,在您Manifest<application>元素添加此聲明...

<meta-data 
     android:name="com.google.android.gms.version" 
     android:value="@integer/google_play_services_version" /> 
0

onResume(),您撥打:

map.moveCamera(CameraUpdateFactory.newLatLngBounds(latlngBounds, width, height, 150)); 

它有時可能返回null。

2.對於

..:E/AndroidRuntime(11838): Caused by: android.view.InflateException:Binary XML file... 

onCreate()

setContentView(R.layout.activity_navigation); 

而且

map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); 

fragmentidmap - 應該在你layoutactivity_navigation - 區分大小寫

<fragment 
android:id="@+id/map" 
class="com.google.android.gms.maps.SupportMapFragment" 
other layout properties /> 

Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml 

的meta標籤在你manifest有關googleplayservices版本,聲明不正確:爲
同樣要申報。預期的版本是4132500,但似乎宣佈爲0
檢查:
http://developer.android.com/guide/topics/manifest/meta-data-element.html

檢查主題,添加谷歌Play服務版本,您的應用程序的清單@

https://developers.google.com/maps/documentation/android/start

<meta-data android:name="com.google.android.gms.version" 
     android:value="@integer/google_play_services_version" /> 
相關問題