如上所述,我试图在我的应用程序中实现googlemaps,并在开始生成地图片段xml时不断收到“错误膨胀类片段”错误。这是片段所在的xml标签:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/activity_main_map_display"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" />
<EditText
android:id="@+id/activity_main_text_edit"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@color/colorWhite"
android:inputType="text"
android:text="@string/activity_main_search_button"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
这是我收到的错误消息(第21行是fragment标签的开头):
> E/AndroidRuntime: FATAL EXCEPTION: main
> Process: com.example.robert.pkpwayfinder, PID: 3947
> java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.robert.pkpwayfinder/com.example.robert.pkpwayfinder.MainActivity}:
> android.view.InflateException: Binary XML file line #21: Binary XML
> file line #21: Error inflating class fragment
> at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3253)
> at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
> at android.app.ActivityThread.access$1100(ActivityThread.java:221)
> at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
> at android.os.Handler.dispatchMessage(Handler.java:102)
> at android.os.Looper.loop(Looper.java:158)
> at android.app.ActivityThread.main(ActivityThread.java:7224)
> at java.lang.reflect.Method.invoke(Native Method)
> at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
> Caused by: android.view.InflateException: Binary XML file line #21: Binary XML file line #21: Error inflating class fragment
> at android.view.LayoutInflater.inflate(LayoutInflater.java:551)
> at android.view.LayoutInflater.inflate(LayoutInflater.java:429)
> at android.view.LayoutInflater.inflate(LayoutInflater.java:380)
> at android.support.v7.app.AppCompatDelegateImpl.setContentView(AppCompatDelegateImpl.java:469)
> at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:140)
> at com.example.robert.pkpwayfinder.MainActivity.onCreate(MainActivity.kt:55)
> at android.app.Activity.performCreate(Activity.java:6876)
> at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1135)
> at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3206)
> at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3349)
> at android.app.ActivityThread.access$1100(ActivityThread.java:221)
> at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1794)
> at android.os.Handler.dispatchMessage(Handler.java:102)
> at android.os.Looper.loop(Looper.java:158)
> at android.app.ActivityThread.main(ActivityThread.java:7224)
> at java.lang.reflect.Method.invoke(Native Method)
> at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
> at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)
答案 0 :(得分:0)
作为一个片段,可以使用documentation下面的XML将该组件添加到活动的布局文件中:
propget
替换此行:
android:name =“ com.google.android.gms.maps.SupportMapFragment”
并确保您添加了依赖项:
<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
答案 1 :(得分:0)
解决方案:
android:class"com.google.android.gms.maps.SupportMapFragment"
Change it like this :
android:name="com.google.android.gms.maps.SupportMapFragment"