扩展SupportMapFragment时出错

时间:2017-11-01 22:06:23

标签: android google-maps android-layout

我试图让一个动作用一张照片显示屏幕的一半,另一半用一张地图拍摄照片。

public class ShowFoto extends AppCompatActivity {

Double latitud;
Double longitud;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.show_foto);
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.mapa);
    mapFragment.getMapAsync(new OnMapReadyCallback() {
        @Override
        public void onMapReady(GoogleMap googleMap) {

        }
    });
}

和xml:

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

<ImageView
    android:id="@+id/imageView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:src="@android:color/transparent"
    />

<fragment
    android:id="@+id/mapa"
    class="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"/>

完整错误

FATAL EXCEPTION: main
                                                                                     Process: com.example.marc.a2252m08_eac3_lluell_g, PID: 11263
                                                                                     java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.marc.a2252m08_eac3_lluell_g/com.example.marc.a2252m08_eac3_lluell_g.ShowFoto}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class fragment
                                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
                                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
                                                                                         at android.app.ActivityThread.-wrap12(ActivityThread.java)
                                                                                         at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
                                                                                         at android.os.Handler.dispatchMessage(Handler.java:102)
                                                                                         at android.os.Looper.loop(Looper.java:154)
                                                                                         at android.app.ActivityThread.main(ActivityThread.java:6077)
                                                                                         at java.lang.reflect.Method.invoke(Native Method)
                                                                                         at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
                                                                                         at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)
                                                                                      Caused by: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class fragment
                                                                                      Caused by: android.view.InflateException: Binary XML file line #0: Error inflating class fragment
                                                                                      Caused by: java.lang.RuntimeException: API key not found.  Check that <meta-data android:name="com.google.android.geo.API_KEY" android:value="your API key"/> is in the <application> element of AndroidManifest.xml
                                                                                         at com.google.maps.api.android.lib6.drd.q.b(:com.google.android.gms.DynamiteModulesB@11509480:40)
                                                                                         at com.google.maps.api.android.lib6.auth.e.a(:com.google.android.gms.DynamiteModulesB@11509480:12)
                                                                                         at com.google.android.gms.maps.internal.CreatorImpl.a(:com.google.android.gms.DynamiteModulesB@11509480:122)
                                                                                         at com.google.android.gms.maps.internal.CreatorImpl.newMapFragmentDelegate(:com.google.android.gms.DynamiteModulesB@11509480:25)
                                                                                         at com.google.android.gms.maps.internal.h.onTransact(:com.google.android.gms.DynamiteModulesB@11509480:32)
                                                                                         at android.os.Binder.transact(Binder.java:499)
                                                                                         at com.google.android.gms.internal.zzeb.zza(Unknown Source)
                                                                                         at com.google.android.gms.maps.internal.zzf.zzaa(Unknown Source)
                                                                                         at com.google.android.gms.maps.MapFragment$zzb.zzatn(Unknown Source)
                                                                                         at com.google.android.gms.maps.MapFragment$zzb.zza(Unknown Source)
                                                                                         at com.google.android.gms.dynamic.zza.zza(Unknown Source)
                                                                                         at com.google.android.gms.dynamic.zza.onInflate(Unknown Source)
                                                                                         at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
                                                                                         at android.app.Fragment.onInflate(Fragment.java:1419)
                                                                                         at android.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2310)
                                                                                         at android.app.FragmentController.onCreateView(FragmentController.java:98)
                                                                                         at android.app.Activity.onCreateView(Activity.java:5884)
                                                                                         at android.support.v4.app.BaseFragmentActivityApi14.onCreateView(BaseFragmentActivityApi14.java:41)
                                                                                         at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:67)
                                                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:777)
                                                                                         at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
                                                                                         at android.view.LayoutInflater.rInflate(LayoutInflater.java:858)
                                                                                         at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
                                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
                                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:426)
                                                                                         at android.view.LayoutInflater.inflate(LayoutInflater.java:377)
                                                                                         at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
                                                                                         at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
                                                                                         at com.example.marc.a2252m08_eac3_lluell_g.ShowFoto.onCreate(ShowFoto.java:29)
                                                                                         at android.app.Activity.performCreate(Activity.java:6662)
                                                                                         at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
                                                                                         at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
                                                                                         at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)

11-01 21:51:09.588 11263-11263 / com.example.marc.a2252m08_eac3_lluell_g E / AndroidRuntime:at android.app.ActivityThread.-wrap12(ActivityThread.java)                                                                                              在android.app.ActivityThread $ H.handleMessage(ActivityThread.java:1460)                                                                                              在android.os.Handler.dispatchMessage(Handler.java:102)                                                                                              在android.os.Looper.loop(Looper.java:154)                                                                                              在android.app.ActivityThread.main(ActivityThread.java:6077)                                                                                              at java.lang.reflect.Method.invoke(Native Method)                                                                                              在com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:866)                                                                                              在com.android.internal.os.ZygoteInit.main(ZygoteInit.java:756)

如果我删除它打开的地图片段而不会崩溃,我已经查看了API文档而没有运气。

1 个答案:

答案 0 :(得分:0)

请在AndroidManifest.xml中提供Api密钥。在Google控制台中检查您的API密钥。