1

I got this error in my layout file with MapFragment

I tried

  • Installing Google Play Service, but still have error

  • Following this solution still does not work

My application is able to run, but when I open a Fragment with MapFragment application stopped working

Full error

Rendering Problems

The following classes could not be instantiated:

- com.google.android.gms.maps.MapFragment (Open Class, Show Exception, Clear Cache)

Tip: Use View.isInEditMode() in your custom views to skip code or show sample data when shown in the IDE.

If this is an unexpected error you can also try to build the project, then manually refresh the layout.

Exception Details

java.lang.NoSuchMethodException: com.google.android.gms.maps.MapFragment.(android.content.Context, android.util.AttributeSet)

  • at java.lang.Class.getConstructor0(Class.java:3082)
  • at java.lang.Class.getConstructor(Class.java:1825)
  • at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:727)
  • at android.view.LayoutInflater.rInflate_Original(LayoutInflater.java:858)
  • at android.view.LayoutInflater_Delegate.rInflate(LayoutInflater_Delegate.java:70)
  • at android.view.LayoutInflater.rInflate(LayoutInflater.java:834)
  • at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:821)
  • at android.view.LayoutInflater.inflate(LayoutInflater.java:518)
  • at android.view.LayoutInflater.inflate(LayoutInflater.java:397)

Copy stack to clipboard

fragment_contact.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="layout.ContactFragment">


    <com.google.android.gms.maps.MapFragment
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/mapFragment"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true" />
</RelativeLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.ng.anthony.mininavigationdrawer" >
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
    <permission
        android:name="com.example.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>
    <uses-permission android:name="com.example.permission.MAPS_RECEIVE"/>

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:screenOrientation="portrait">
        <activity
            android:name="com.th.ac.sd.MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

build.gradle (app)

apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion "23.0.2"
    0
    defaultConfig {
        applicationId "com.th.ac.sd"
        minSdkVersion 21
        targetSdkVersion 25
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support:design:25.2.0'
    compile 'com.android.support:support-v4:25.2.0'
    testCompile 'junit:junit:4.12'
    compile 'com.google.android.gms:play-services-maps:10.2.0'
}

Installed SDK tools

enter image description here

Community
  • 1
  • 1
phwt
  • 1,356
  • 1
  • 22
  • 42

1 Answers1

1
tools:context="layout.ContactFragment">

    <com.google.android.gms.maps.MapFragment

You have a Fragment in a Fragment.

Android doesn't really like that, so wherever you put <fragment class="layout.ContactFragment"> (assuming you did), you can replace that with a Google Map Fragment since the only view you have in this ContactFragment is a Map Fragment anyway.

Otherwise, you can use a FrameLayout and dynamically load a new SupportMapFragment just like any other Fragment.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245