0

I believe it is possible to setContentView() to a map fragment while extending AppCompatActivity. However I need to extend a Base Activity which extends AppCompatActivity. This means that I need to inflate my map fragment with a container. Unfortunately it throws this exception every time:

Caused by: android.view.InflateException: Binary XML file line #7: Class is not a View com.google.android.gms.maps.SupportMapFragment

Do I have to choose or is there a way to work around this problem?

I am creating an app that needs to access a map while still keep certain functions like the navigation drawer hence I have a Base Activity.

Emmanuel Conradie
  • 345
  • 1
  • 5
  • 20

2 Answers2

0

Since you didn't provided code I am just guessing here, but from the error you posted you are probably doing this in your XML:

<com.google.android.gms.maps.SupportMapFragment
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

SupportMapFragment isn't a view, it is fragment, so you should place it using the fragment tag, as following:

<fragment
    class="com.google.android.gms.maps.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
jonathanrz
  • 4,206
  • 6
  • 35
  • 58
  • Unfortunately I still get thrown with this error: Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment. I never know about adding in a class view like this but I have an idea the problem lies with the inflater. – Emmanuel Conradie May 20 '18 at 06:38
  • This would work if you extend Fragment activity class, I am try to find a way around this. – Emmanuel Conradie May 20 '18 at 06:46
0

For anyone who still has this problem after migrating to SDK v28, here's something that might help: https://stackoverflow.com/a/34798398/4483494

Essentially, if you have already defined in your application manifest the key "com.google.android.geo.API_KEY", you should delete the key "com.google.android.maps.v2.API_KEY".

ArturT
  • 92
  • 1
  • 2