androidgoogle-mapsmapactivity

Unfortunately myAndroidapp has stopped . App include maps


I am trying to build a google map app on my android device. It was working fine but lately it has been giving error.

The app gives error FATAL:MAIN. I am posting the code and the log errors file. Please help me through this. Is there any problem with my android device because the same code was working fine for me. Android Manifest :-

 <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.googlemaps"
    android:versionCode="1"
    android:versionName="1.0" >
       <uses-sdk android:minSdkVersion="8" 
    android:targetSdkVersion="17"/>
    <application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name" >

    <!--  Add Google Map Library -->
    <uses-library android:name="com.google.android.maps" />

    <activity
        android:label="@string/app_name"
        android:name=".MapsActivity" >
        <intent-filter >
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <meta-data
        android:name="com.google.android.maps.v2.API_KEY"
        android:value="AIzaSyBX1XULUbZ8KEpvy60JsDKxmYWtVuIs2X0"/>
    </application>
    <uses-feature
    android:glEsVersion="0x00020000"
    android:required="true"/>
    <permission android:name="com.example.googlemaps.permission.MAPS_RECEIVE"                   android:protectionLevel="signature"/>
    <uses-permission android:name="com.example.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" />



      </manifest>

MapActivity.java

 package com.example.googlemaps;
 import android.app.Dialog;
 import android.os.Bundle;
 import android.support.v4.app.FragmentActivity;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
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;


public class MapsActivity extends FragmentActivity {
     //Intent in = getIntent();
     //String latitude = in.getStringExtra("latitude");
     //String longitude = in.getStringExtra("longitude");


    GoogleMap googleMap;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // Getting Google Play availability status
        int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

        // Showing status
        if(status!=ConnectionResult.SUCCESS){ // Google Play Services are not available

            int requestCode = 10;
            Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
            dialog.show();

        }else { // Google Play Services are available


            // Double latitude1=Double.parseDouble(latitude);
            // Double longitude1=Double.parseDouble(longitude);

            // Getting reference to the SupportMapFragment of activity_main.xml
            SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

            // Getting GoogleMap object from the fragment
            googleMap = fm.getMap();

            // Enabling MyLocation Layer of Google Map
            googleMap.setMyLocationEnabled(true);

            googleMap.addMarker(new MarkerOptions().position(new LatLng(28.62293,77.36403)).title("SaveMe").snippet("Place of Interest").icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));

                //System.out.println("Marker added");


            // Showing the current location in Google Map
            googleMap.moveCamera(CameraUpdateFactory.newLatLng(new LatLng(28.62293, 77.36403)));

            // Zoom in the Google Map
            googleMap.animateCamera(CameraUpdateFactory.zoomTo(14));

            // Setting latitude and longitude in the TextView tv_location
        }
    }




}

mail.xml:-

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <fragment
        android:name="com.google.android.gms.maps.SupportMapFragment"

        android:id="@+id/map"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>

Errors:-

05-09 11:28:37.156: W/dalvikvm(27963): threadid=1: thread exiting with uncaught exception (group=0x40aa1210)
05-09 11:28:37.156: E/AndroidRuntime(27963): FATAL EXCEPTION: main
05-09 11:28:37.156: E/AndroidRuntime(27963): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
05-09 11:28:37.156: E/AndroidRuntime(27963):    at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:739)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:255)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.app.Activity.setContentView(Activity.java:1835)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at com.example.googlemaps.MapsActivity.onCreate(MapsActivity.java:28)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.app.Activity.performCreate(Activity.java:4465)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.os.Looper.loop(Looper.java:137)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at android.app.ActivityThread.main(ActivityThread.java:4441)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at java.lang.reflect.Method.invokeNative(Native Method)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at java.lang.reflect.Method.invoke(Method.java:511)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
05-09 11:28:37.156: E/AndroidRuntime(27963):    at dalvik.system.NativeStart.main(Native Method)

Solution

  • The code is working assuming that you have referenced the support library and google play services correctly. It is showing block A of sector 32. Have a look at this on how to include maps in your application.