在我的应用程序中获取错误“java.lang.RuntimeException:无法启动活动”

我的申请昨天工作,我无法弄清楚为什么它停止工作。 我唯一想做的就是创建一个签名的apk。 为此,我必须创建一个新的Google地图密钥并将其放入清单文件中。 我按照Google开发人员教程完成了这项工作。 但是现在当我尝试运行它启动时,我点击一个按钮就会强行关闭。

这是错误日志:

03-20 23:31:33.636 10036-10036/project.sharethefare E/AndroidRuntime﹕ FATAL EXCEPTION: main Process: project.sharethefare, PID: 10036 java.lang.RuntimeException: Unable to start activity ComponentInfo{project.sharethefare/project.sharethefare.CurrentLocation}: android.view.InflateException: Binary XML file line #9: Error inflating class fragment at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2658) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2725) at android.app.ActivityThread.access$900(ActivityThread.java:172) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422) at android.os.Handler.dispatchMessage(Handler.java:102) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5834) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183) Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class fragment at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:770) at android.view.LayoutInflater.rInflate(LayoutInflater.java:813) at android.view.LayoutInflater.inflate(LayoutInflater.java:511) at android.view.LayoutInflater.inflate(LayoutInflater.java:415) at android.view.LayoutInflater.inflate(LayoutInflater.java:366) at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:428) at android.app.Activity.setContentView(Activity.java:2241) at project.sharethefare.CurrentLocation.onCreate(CurrentLocation.java:24) at android.app.Activity.performCreate(Activity.java:6221) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2611)             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2725)             at android.app.ActivityThread.access$900(ActivityThread.java:172)             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422)             at android.os.Handler.dispatchMessage(Handler.java:102)             at android.os.Looper.loop(Looper.java:145)             at android.app.ActivityThread.main(ActivityThread.java:5834)             at java.lang.reflect.Method.invoke(Native Method)             at java.lang.reflect.Method.invoke(Method.java:372)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183) Caused by: java.lang.RuntimeException: The API key can only be specified once. It is recommended that you use the meta-data tag with the name: com.google.android.maps.v2.API_KEY in the  element of AndroidManifest.xml at com.google.maps.api.android.lib6.gmm6.cga(Unknown Source) at com.google.maps.api.android.lib6.cia(Unknown Source) at com.google.maps.api.android.lib6.c.el.a(Unknown Source) at com.google.maps.api.android.lib6.c.ab.a(Unknown Source) at com.google.maps.api.android.lib6.c.aa.a(Unknown Source) at com.google.android.gms.maps.internal.x.onTransact(SourceFile:107) at android.os.Binder.transact(Binder.java:380) at com.google.android.gms.maps.internal.IMapFragmentDelegate$a$a.onCreateView(Unknown Source) at com.google.android.gms.maps.SupportMapFragment$a.onCreateView(Unknown Source) at com.google.android.gms.dynamic.a$4.b(Unknown Source) at com.google.android.gms.dynamic.aa(Unknown Source) at com.google.android.gms.dynamic.a.onCreateView(Unknown Source) at com.google.android.gms.maps.SupportMapFragment.onCreateView(Unknown Source) at android.support.v4.app.Fragment.performCreateView(Fragment.java:1786) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:920) at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104) at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1206) at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2159) at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:297) at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)             at android.view.LayoutInflater.rInflate(LayoutInflater.java:813)             at android.view.LayoutInflater.inflate(LayoutInflater.java:511)             at android.view.LayoutInflater.inflate(LayoutInflater.java:415)             at android.view.LayoutInflater.inflate(LayoutInflater.java:366)             at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:428)             at android.app.Activity.setContentView(Activity.java:2241)             at project.sharethefare.CurrentLocation.onCreate(CurrentLocation.java:24)             at android.app.Activity.performCreate(Activity.java:6221)             at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1119)             at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2611)             at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2725)             at android.app.ActivityThread.access$900(ActivityThread.java:172)             at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1422)             at android.os.Handler.dispatchMessage(Handler.java:102)             at android.os.Looper.loop(Looper.java:145)             at android.app.ActivityThread.main(ActivityThread.java:5834)             at java.lang.reflect.Method.invoke(Native Method)             at java.lang.reflect.Method.invoke(Method.java:372)             at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1388)             at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1183) 

这是CurrentLocation类:

  package project.sharethefare; import android.content.Intent; import android.support.v4.app.FragmentActivity; import android.os.Bundle; 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.LatLng; import android.location.Location; import android.view.View; public class CurrentLocation extends FragmentActivity { private GoogleMap mMap; // Might be null if Google Play services APK is not available. //________________________________________________________________________________________ @Override protected void onCreate(Bundle savedInstanceState) { //auto generated super.onCreate(savedInstanceState); setContentView(R.layout.activity_current_location); setUpMapIfNeeded(); //part of google maps api mMap.setMyLocationEnabled(true); //creates a new HomeScreen } @Override protected void onResume() { //Auto Generated super.onResume(); setUpMapIfNeeded(); //set up map if not already created } /** * Sets up the map if it is possible to do so (ie, the Google Play services APK is correctly * installed) and the map has not already been instantiated.. This will ensure that we only ever * call {@link #setUpMap()} once when {@link #mMap} is not null. * 

* If it isn't installed {@link SupportMapFragment} (and * {@link com.google.android.gms.maps.MapView MapView}) will show a prompt for the user to * install/update the Google Play services APK on their device. *

* A user can return to this FragmentActivity after following the prompt and correctly * installing/updating/enabling the Google Play services. Since the FragmentActivity may not * have been completely destroyed during this process (it is likely that it would only be * stopped or paused), {@link #onCreate(Bundle)} may not be called again so we should call this * method in {@link #onResume()} to guarantee that it will be called. */ private void setUpMapIfNeeded() { // Do a null check to confirm that we have not already instantiated the map. if (mMap == null) { // Try to obtain the map from the SupportMapFragment. mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.curLocMap)) .getMap(); // Check if we were successful in obtaining the map. if (mMap != null) { setUpMap(); } } } /** * This is where we can add markers or lines, add listeners or move the camera. In this case, we * just add a marker near Africa. *

* This should only be called once and when we are sure that {@link #mMap} is not null. */ //call the method to continuously check current location private void setUpMap() { mMap.setOnMyLocationChangeListener(myLocationChangeListener); } //called above. Used to constantly update the users position on the map private GoogleMap.OnMyLocationChangeListener myLocationChangeListener = new GoogleMap.OnMyLocationChangeListener() { @Override public void onMyLocationChange(Location location) { //create a new latitude and longitude point LatLng loc = new LatLng(location.getLatitude(), location.getLongitude()); //make global variables on home screen == to current location HomeScreen.curLat = location.getLatitude(); HomeScreen.curLong = location.getLongitude(); HomeScreen.curLocSet = true; //animate the camera to zoom in on position when found mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(loc, 16.0f)); } }; public void backToHome(View view){ // called when button clicked. returns to homeScreen activity Intent intent = new Intent(CurrentLocation.this,HomeScreen.class); startActivity(intent); } }

这是相应的xml文件:

    

这是清单文件:

                                   

 Caused by: java.lang.RuntimeException: The API key can only be specified once. It is recommended that you use the meta-data tag with the name: com.google.android.maps.v2.API_KEY in the  element of AndroidManifest.xml 

根据错误消息,从清单中删除它:

  

如果您在应用程序中同时使用Maps&Places Api,则只需指定geo api密钥

  

两个apis都能正常工作。你不能同时使用谷歌api的元数据标签。

在我的情况下,我有谷歌地图地方APIPlaceLikelihoodBuffer )。

清单文件不支持 Google API密钥的 两个元数据

我已经为Map评论了Google地图API密钥。 如下所示:

    

幸运的是, Google MapPlace APIPlaceLikelihoodBuffer )都适合我。

奇怪但真实。

希望这会帮助你。