0

I know there are a lot of questions like this one, and I searched everything I could, but I wasn't able to find an answer. So, I think I did everything well, but it's still giving me this error.

main.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" >

<fragment
    android:id="@+id/map"
    android:name="com.google.android.gms.maps.MapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</RelativeLayout>

MainActivity.java:

package com.davidmilicevic97.testapp;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends Activity {

private GoogleMap googleMap;

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

    try {
        initializeMap();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

@Override
protected void onResume() {
    super.onResume();
    initializeMap();
}

private void initializeMap() {
    if (googleMap == null) {
        googleMap = ((MapFragment) getFragmentManager().findFragmentById(
                R.id.map)).getMap();

        if (googleMap == null) {
            Toast.makeText(getApplicationContext(),
                    "Sorry! Unable to create maps.", Toast.LENGTH_SHORT)
                    .show();
        }
    }
}

}

AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.davidmilicevic97.testapp"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="14"
    android:targetSdkVersion="15" />

<permission
    android:name="com.davidmilicevic97.testapp.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-permission android:name="com.davidmilicevic97.testapp.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<!-- Required OpenGL ES 2.0. for Maps v2 -->
<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

    <!-- Google API key -->
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="myKey" />
    <!-- Play services version -->
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
</application>

And here is my log, if it's needed:

    07-07 16:29:22.502: E/Trace(8412): error opening trace file: No such file or directory (2)
07-07 16:29:22.502: E/dalvikvm(8412): Could not find class 'com.google.android.gms.maps.MapFragment', referenced from method com.davidmilicevic97.testapp.MainActivity.initializeMap
07-07 16:29:22.502: W/dalvikvm(8412): VFY: unable to resolve check-cast 929 (Lcom/google/android/gms/maps/MapFragment;) in Lcom/davidmilicevic97/testapp/MainActivity;
07-07 16:29:22.502: D/dalvikvm(8412): VFY: replacing opcode 0x1f at 0x000f
07-07 16:29:23.502: E/ActivityThread(8412): Failed to inflate
07-07 16:29:23.502: E/ActivityThread(8412): android.view.InflateException: Binary XML file line #6: Error inflating class fragment
07-07 16:29:23.502: E/ActivityThread(8412):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
07-07 16:29:23.502: E/ActivityThread(8412):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
07-07 16:29:23.502: E/ActivityThread(8412):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-07 16:29:23.502: E/ActivityThread(8412):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-07 16:29:23.502: E/ActivityThread(8412):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-07 16:29:23.502: E/ActivityThread(8412):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:275)
07-07 16:29:23.502: E/ActivityThread(8412):     at android.app.Activity.setContentView(Activity.java:1867)
07-07 16:29:23.502: E/ActivityThread(8412):     at com.davidmilicevic97.testapp.MainActivity.onCreate(MainActivity.java:17)
07-07 16:29:23.502: E/ActivityThread(8412):     at android.app.Activity.performCreate(Activity.java:5008)
07-07 16:29:23.502: E/ActivityThread(8412):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
07-07 16:29:23.502: E/ActivityThread(8412):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
07-07 16:29:23.502: E/ActivityThread(8412):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
07-07 16:29:23.502: E/ActivityThread(8412):     at android.app.ActivityThread.access$600(ActivityThread.java:142)
07-07 16:29:23.502: E/ActivityThread(8412):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
07-07 16:29:23.502: E/ActivityThread(8412):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-07 16:29:23.502: E/ActivityThread(8412):     at android.os.Looper.loop(Looper.java:137)
07-07 16:29:23.502: E/ActivityThread(8412):     at android.app.ActivityThread.main(ActivityThread.java:4931)
07-07 16:29:23.502: E/ActivityThread(8412):     at java.lang.reflect.Method.invokeNative(Native Method)
07-07 16:29:23.502: E/ActivityThread(8412):     at java.lang.reflect.Method.invoke(Method.java:511)
07-07 16:29:23.502: E/ActivityThread(8412):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
07-07 16:29:23.502: E/ActivityThread(8412):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
07-07 16:29:23.502: E/ActivityThread(8412):     at dalvik.system.NativeStart.main(Native Method)
07-07 16:29:23.502: E/ActivityThread(8412): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
07-07 16:29:23.502: E/ActivityThread(8412):     at android.app.Fragment.instantiate(Fragment.java:584)
07-07 16:29:23.502: E/ActivityThread(8412):     at android.app.Fragment.instantiate(Fragment.java:552)
07-07 16:29:23.502: E/ActivityThread(8412):     at android.app.Activity.onCreateView(Activity.java:4656)
07-07 16:29:23.502: E/ActivityThread(8412):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
07-07 16:29:23.502: E/ActivityThread(8412):     ... 21 more
07-07 16:29:23.502: E/ActivityThread(8412): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
07-07 16:29:23.502: E/ActivityThread(8412):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
07-07 16:29:23.502: E/ActivityThread(8412):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-07 16:29:23.502: E/ActivityThread(8412):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-07 16:29:23.502: E/ActivityThread(8412):     at android.app.Fragment.instantiate(Fragment.java:574)
07-07 16:29:23.502: E/ActivityThread(8412):     ... 24 more
07-07 16:29:23.502: D/AndroidRuntime(8412): Shutting down VM
07-07 16:29:23.502: W/dalvikvm(8412): threadid=1: thread exiting with uncaught exception (group=0x2b54a300)
07-07 16:29:23.502: E/AndroidRuntime(8412): FATAL EXCEPTION: main
07-07 16:29:23.502: E/AndroidRuntime(8412): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.davidmilicevic97.testapp/com.davidmilicevic97.testapp.MainActivity}: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
07-07 16:29:23.502: E/AndroidRuntime(8412):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2185)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2210)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at android.app.ActivityThread.access$600(ActivityThread.java:142)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1208)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at android.os.Handler.dispatchMessage(Handler.java:99)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at android.os.Looper.loop(Looper.java:137)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at android.app.ActivityThread.main(ActivityThread.java:4931)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at java.lang.reflect.Method.invokeNative(Native Method)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at java.lang.reflect.Method.invoke(Method.java:511)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:791)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:558)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at dalvik.system.NativeStart.main(Native Method)
07-07 16:29:23.502: E/AndroidRuntime(8412): Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
07-07 16:29:23.502: E/AndroidRuntime(8412):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:275)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at android.app.Activity.setContentView(Activity.java:1867)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at com.davidmilicevic97.testapp.MainActivity.onCreate(MainActivity.java:17)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at android.app.Activity.performCreate(Activity.java:5008)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2139)
07-07 16:29:23.502: E/AndroidRuntime(8412):     ... 11 more
07-07 16:29:23.502: E/AndroidRuntime(8412): Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
07-07 16:29:23.502: E/AndroidRuntime(8412):     at android.app.Fragment.instantiate(Fragment.java:584)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at android.app.Fragment.instantiate(Fragment.java:552)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at android.app.Activity.onCreateView(Activity.java:4656)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
07-07 16:29:23.502: E/AndroidRuntime(8412):     ... 21 more
07-07 16:29:23.502: E/AndroidRuntime(8412): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
07-07 16:29:23.502: E/AndroidRuntime(8412):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
07-07 16:29:23.502: E/AndroidRuntime(8412):     at android.app.Fragment.instantiate(Fragment.java:574)
07-07 16:29:23.502: E/AndroidRuntime(8412):     ... 24 more

I imported google-play-services_lib through the Eclipse and used it as a library for my project. I think i don't have to use SupportMapFragment because my MinSdkVersion is 14. Also, I added both Google Play Services version and API key to my manifest, and I think I added all permissions I had to, so I really don't know where is the problem.

I would be very grateful if anyone could check my problem.

1 Answers1

0

This is more of a comment, but I cannot yet comment, so here goes:

In v2 for google maps, you don't need the following lines:

<permission
android:name="com.davidmilicevic97.testapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.davidmilicevic97.testapp.permission.MAPS_RECEIVE" />

I don't see anything wrong with your code (the code should run even with the above, they are ignored).

This could very well be an Eclipse issue. So the following is from my experience, you might want to give it a go:

First, do a 'clean' and build. Second, in the Properties>Android of your project, select Google APIs and apply and then change to Android API and apply again.

I've had issues several times where my project wouldn't properly build, but doing the above seems to do a 'reset'. You might even want to restart Eclipse.

Hahn
  • 424
  • 3
  • 11