Search code examples
androidexceptionclassnotfoundexception

Android Google Map classNotFound exception


Basically I am trying to make an app which displays a Google Map.Here is my code.

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/LinearLayout1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
   <com.google.android.maps.MapView
    android:id="@+id/mapView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:enabled="true"
    android:clickable="true"
    android:apiKey="my key goes here"
    />
</LinearLayout>

MainActivity class...

import com.google.android.maps.MapActivity;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends MapActivity {

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

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
   }


}

When I run it,I get the following message

06-22 15:54:03.622: E/AndroidRuntime(26187): FATAL EXCEPTION: main
06-22 15:54:03.622: E/AndroidRuntime(26187): java.lang.RuntimeException: 
Unable to    instantiate activity
ComponentInfo{com.example.maptutorial/com.example.maptutorial.MainActivity}: 
java.lang.ClassNotFoundException: com.example.maptutorial.MainActivity

Perhaps I might be doing something wrong in my Manifest File,and can not see it..

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

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />

<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.maptutorial.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>
  </application>

</manifest>

Solution

  • I think you are using MAP API version 1 which is deprecated. Why Cant you use API 2 either Fragment or support-fragment (https://developers.google.com/maps/documentation/android/start)

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

    Manifest file

    <uses-feature
        android:glEsVersion="0x00020000"
        android:required="true" />
    <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyC8qEhdHVd3ZtxCR0549UqwnM72h0jgoMY" />