1

I know this questions has already been asked hundreds of times, and it feels like I've been through them all without finding an answer.

I've been follwing an answer on how to add a marker to googlemaps.How to add overlay in google maps API v2 | Android |

I get no errors but when i run the app i get "program has stopped" and I get these errors in logcat:

01-08 13:22:20.658: W/dalvikvm(9338): threadid=1: thread exiting with uncaught exception (group=0x40c701f8)
01-08 13:22:20.663: E/AndroidRuntime(9338): FATAL EXCEPTION: main
01-08 13:22:20.663: E/AndroidRuntime(9338): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.googlemaps/com.googlemaps.MainActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
01-08 13:22:20.663: E/AndroidRuntime(9338):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at android.app.ActivityThread.access$600(ActivityThread.java:127)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at android.os.Looper.loop(Looper.java:137)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at android.app.ActivityThread.main(ActivityThread.java:4511)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at java.lang.reflect.Method.invokeNative(Native Method)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at java.lang.reflect.Method.invoke(Method.java:511)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:980)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:747)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at dalvik.system.NativeStart.main(Native Method)
01-08 13:22:20.663: E/AndroidRuntime(9338): Caused by: android.view.InflateException: Binary XML file line #9: Error inflating class fragment
01-08 13:22:20.663: E/AndroidRuntime(9338):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:272)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at android.app.Activity.setContentView(Activity.java:1835)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at com.googlemaps.MainActivity.onCreate(MainActivity.java:19)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at android.app.Activity.performCreate(Activity.java:4470)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
01-08 13:22:20.663: E/AndroidRuntime(9338):     ... 11 more
01-08 13:22:20.663: E/AndroidRuntime(9338): Caused by: android.support.v4.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.supportMapFragment: make sure class name exists, is public, and has an empty constructor that is public
01-08 13:22:20.663: E/AndroidRuntime(9338):     at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
01-08 13:22:20.663: E/AndroidRuntime(9338):     ... 21 more
01-08 13:22:20.663: E/AndroidRuntime(9338): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.supportMapFragment
01-08 13:22:20.663: E/AndroidRuntime(9338):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-08 13:22:20.663: E/AndroidRuntime(9338):     at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
01-08 13:22:20.663: E/AndroidRuntime(9338):     ... 24 more

Here's my main java:

package com.googlemaps;

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

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

public class MapActivity extends FragmentActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
            setContentView(R.layout.activity_main); 
    LatLng sala = new LatLng(59.918434,16.618195);

    GoogleMap mMap;
    mMap = ((SupportMapFragment)(getSupportFragmentManager().findFragmentById(android.R.id.content))).getMap();
    mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    mMap.addMarker(new MarkerOptions()
            .position(sala)
            .title("Här ligger sala")
            .snippet("Detta är sala")
            .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE)));
    mMap.getUiSettings().setCompassEnabled(true);
    mMap.getUiSettings().setZoomControlsEnabled(true);
    mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(sala,10));


}

And here's my xml:

<?xml version="1.0" encoding="utf-8"?>

<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=".MainActivity" >

<fragment 
    android:id="@+id/map"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.supportMapFragment"

    />
</RelativeLayout>

and also my manifest:

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

    <uses-sdk
        android:minSdkVersion="14"
        android:targetSdkVersion="17" />
    <permission
        android:name="com.googlemaps.permission.MAPS_RECEIVE"
        android:protectionLevel="signature"/>

    <uses-permission android:name="com.googlemaps.permission.MAPS_RECEIVE" />
    <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"/>
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>


    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <uses-library android:required="true"
            android:name="com.google.android.maps" />
        <activity
            android:name="com.go8oglemaps.MapActivity"
            android:label="@string/app_name" 
            android:screenOrientation="portrait">

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <!-- adds google API key to manifest -->
        <meta-data 
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyDSVPzsvOratkVZoMEKa0sF_GLOtcFI7yg"
            />
    </application>

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
</manifest>
6
  • could you please post your Manifest File? Commented Jan 8, 2013 at 11:27
  • Updated with full logcat and manifest file. Commented Jan 8, 2013 at 11:36
  • Change the android name to the right package as in your java file! Commented Jan 8, 2013 at 11:39
  • I changed the android name to the right package file name, but I still get the same error in logcat,except for: Unable to instantiate activity I get: java.lang.RuntimeException: Unable to start activity in logcat. Commented Jan 8, 2013 at 11:52
  • 1
    post your complete new logcat after you changed the package name Commented Jan 8, 2013 at 11:55

2 Answers 2

1

on your manifest change the name of your MapActivty. Theres a spelling mistake.

android:name="com.go8oglemaps.MapActivity"
Sign up to request clarification or add additional context in comments.

2 Comments

Oh thanks, didn't see that before posting the other answer. Still getting same error as before though.
your package is "com.googlemaps" but in your manifest you have typed com.go8oglemaps". That maybe the error causing your app to crash
0
setContentView(R.layout.your_xml_file);

add the above line after super.onCreate(savedInstanceState); in your onCreate() and update the result.

8 Comments

Sorry for taking such a long time to answer, my internet died on me. I updated logcat and java using your answer, and I seem to get some errors related to fragments. Any idea on the problem?
Make sure that you have added the Google Play Services Android library project to your application, where that class is defined. Also make sure that you are running your app on an API Level 11 or higher environment, since you are attempting to use native fragments (rather than the Android Support package's backport).
You are extending FragmentActivity, indicating that you are trying to use the Android Support package backport of fragments. However, your <fragment> element refers to MapFragment, which is for the native API Level 11 edition of fragments. Replace MapFragment with SupportMapFragment.
In can't see where i should replace MapFragment with SupportMapFragment, in my <fragment> I'm referring to the supportMapFragment class of the google_play_services_lib.
Ok that part is right. Have you added Google Play Service Android library project to your application?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.