0

I try to create a simple GoogleMap by Using Google Play Service and Google Maps API. But all the times I get errors...

I´m working with IntelliJ 12.1, here my full Code:

RecorderMap.java

package com.example.GPSApp;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

public class RecorderMap extends FragmentActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map);

}
}

map.xml

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.maps.SupportMapFragment
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.GPSApp"
          android:versionCode="1"
          android:versionName="1.0">
    <uses-sdk
            android:minSdkVersion="10"
            android:targetSdkVersion="16" />

    <permission
            android:name="com.example.GPSApp.permission.MAPS_RECEIVE"
            android:protectionLevel="signature" />

    <uses-permission android:name="com.example.newmapview.permission.MAPS_RECEIVE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

    <uses-feature android:name="android.hardware.location.gps" />
    <uses-feature
            android:glEsVersion="0x00020000"
            android:required="true" />

    <application android:label="@string/app_name">
        <uses-library android:name="com.google.android.maps" />
        <activity android:name=".MainActivity"
                  android:label="@string/app_name"
                  android:theme="@android:style/Theme.NoTitleBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <activity android:name=".RecorderMap"
                  android:label="@string/app_name"
                  android:theme="@android:style/Theme.NoTitleBar"/>
        <meta-data
                android:name="com.google.android.maps.v2.API_KEY"
                android:value="XXX" />
    </application>
</manifest>

I think the Problem is how I include the GooGlePlayService... I´ve tried to add as module, as libary as External Libary but I don't know how to include and to use it right... :(

EDIT: LogCat

08-28 07:41:59.869: ERROR/AndroidRuntime(23080): FATAL EXCEPTION: main
        java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.GPSApp/com.example.GPSApp.RecorderMap}: android.view.InflateException: Binary XML file line #2: Error inflating class com.google.android.gms.maps.SupportMapFragment
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
        at android.app.ActivityThread.access$1500(ActivityThread.java:117)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:130)
        at android.app.ActivityThread.main(ActivityThread.java:3683)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:507)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
        at dalvik.system.NativeStart.main(Native Method)
        Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class com.google.android.gms.maps.SupportMapFragment
        at android.view.LayoutInflater.createView(LayoutInflater.java:508)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:210)
        at android.app.Activity.setContentView(Activity.java:1660)
        at com.example.GPSApp.RecorderMap.onCreate(RecorderMap.java:18)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
        ... 11 more
        Caused by: java.lang.NoSuchMethodException: SupportMapFragment(Context,AttributeSet)
        at java.lang.Class.getMatchingConstructor(Class.java:643)
        at java.lang.Class.getConstructor(Class.java:472)
        at android.view.LayoutInflater.createView(LayoutInflater.java:480)
        ... 20 more

****EDIT2** Problem solved by using this: java.lang.noclassdeffounderror: com.google.android.gms.R$styleable**

Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

The only thing I find missing in your RecorderMap.java file is that you haven't imported the SupportFragment class. So add this line to it

import com.google.android.gms.maps.SupportMapFragment;

If that doesn't work, then check out the following.

From what you are saying, it means you have already installed the google play services. If not, then try installing it using this link http://developer.android.com/google/play-services/setup.html

After that, referencing the google play services library should be as easy as editing your build.gradle file. The current version of android studio makes this possible. Under dependencies in your build.gradle file, add the following code

compile 'com.google.android.gms:play-services:3.1.36'

You seem to have your API key intact.

Finally, remember you need to test your app on an actual android device and not an emulator. The android API version 2 is not yet able to display maps on emulators.

I think this should be okay for your app to work.

Osei-Bonsu Christian
  • 2,935
  • 1
  • 15
  • 8