3

I tried from three days but my problem is not resolved!, I was making an app using Google API maps v2, I activated it successfully...

Now when I run my program it's showing this error: "Unfortunately, apps has stopped"

please help what kind of error is this ??

Here is a manifest file:

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

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

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

    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<!-- The following two permissions are not required to use
     Google Maps Android API v2, but are recommended. -->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

    <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="com.example.maps.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>

        <meta-data
            android:name="com.google.android.maps.v2.API_KEY"
            android:value="AIzaSyCKewNqqmmp2gwcLuefCAXrTRdQjm-6t-U" />
    </application>

</manifest>

Here is activity_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"
    tools:context=".MainActivity">

    <fragment
        android:id="@+id/map"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:name="com.google.android.gms.maps.SupportMapFragment"
        android:clickable="true" />

</RelativeLayout>

Here is a MainActivity:

package com.example.maps;

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

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

public class MainActivity extends FragmentActivity{

SupportMapFragment mMap;
private GoogleMap googleMap;

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

    googleMap = (SupportMapFragment) getSupportFragmentManager() //Now, here showing an error "cannot convert from SupportMapFragment to GoogleMap" and can't run this program.
            .findFragmentById(R.id.map).getMap();
  }
}

Here is a log cat file:

02-19 05:08:50.393: I/Process(1405): Sending signal. PID: 1405 SIG: 9
02-19 05:15:42.608: E/dalvikvm(1447): Could not find class 'com.google.android.gms.maps.SupportMapFragment', referenced from method com.example.maps.MainActivity.onCreate
02-19 05:15:42.608: E/dalvikvm(1447): Could not find class 'com.google.android.gms.maps.SupportMapFragment', referenced from method com.example.maps.MainActivity.onCreate
02-19 05:15:42.608: W/dalvikvm(1447): VFY: unable to resolve check-cast 728 (Lcom/google/android/gms/maps/SupportMapFragment;) in Lcom/example/maps/MainActivity;
02-19 05:15:42.696: D/dalvikvm(1447): VFY: replacing opcode 0x1f at 0x0012
02-19 05:15:43.308: D/AndroidRuntime(1447): Shutting down VM
02-19 05:15:43.308: W/dalvikvm(1447): threadid=1: thread exiting with uncaught exception (group=0xa4be8648)
02-19 05:15:43.348: E/AndroidRuntime(1447): FATAL EXCEPTION: main
02-19 05:15:43.348: E/AndroidRuntime(1447): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.maps/com.example.maps.MainActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
02-19 05:15:43.348: E/AndroidRuntime(1447):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2211)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at android.app.ActivityThread.access$600(ActivityThread.java:141)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at android.os.Looper.loop(Looper.java:137)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at android.app.ActivityThread.main(ActivityThread.java:5103)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at java.lang.reflect.Method.invokeNative(Native Method)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at java.lang.reflect.Method.invoke(Method.java:525)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at dalvik.system.NativeStart.main(Native Method)
02-19 05:15:43.348: E/AndroidRuntime(1447): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
02-19 05:15:43.348: E/AndroidRuntime(1447):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at android.app.Activity.setContentView(Activity.java:1895)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at com.example.maps.MainActivity.onCreate(MainActivity.java:17)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at android.app.Activity.performCreate(Activity.java:5133)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
02-19 05:15:43.348: E/AndroidRuntime(1447):     ... 11 more
02-19 05:15:43.348: E/AndroidRuntime(1447): Caused by: android.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
02-19 05:15:43.348: E/AndroidRuntime(1447):     at android.app.Fragment.instantiate(Fragment.java:592)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at android.app.Fragment.instantiate(Fragment.java:560)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at android.app.Activity.onCreateView(Activity.java:4738)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
02-19 05:15:43.348: E/AndroidRuntime(1447):     ... 21 more
02-19 05:15:43.348: E/AndroidRuntime(1447): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.google.android.gms.maps.SupportMapFragment" on path: DexPathList[[zip file "/data/app/com.example.maps-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.maps-2, /system/lib]]
02-19 05:15:43.348: E/AndroidRuntime(1447):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:53)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
02-19 05:15:43.348: E/AndroidRuntime(1447):     at android.app.Fragment.instantiate(Fragment.java:582)
02-19 05:15:43.348: E/AndroidRuntime(1447):     ... 24 more
02-19 05:15:53.760: I/Process(1447): Sending signal. PID: 1447 SIG: 9
Daniel Nugent
  • 43,104
  • 15
  • 109
  • 137
user3326455
  • 29
  • 1
  • 6

4 Answers4

0

In your code you should inflate your map in GoogleMap which is already itself have now became Fragment besides that your are inflating it into SupportMapFragment.

Change your below lines :

 mMap = (SupportMapFragment) getSupportFragmentManager()
    .findFragmentById(R.id.map);

    googleMap = mMap.getMap();

To as below:

 googleMap = (SupportMapFragment) getSupportFragmentManager()
    .findFragmentById(R.id.map).getMap();

Use the instance of GoogleMap not the SupportMapFragment. As if you will use SupportMapFragment it will always go for searching the for the class which you have defined for that Fragment in your layout. And will search for the method of getMap(), Which is the method of GoogleMap class only.

EDITED:

Make sure the below libraries are there in your projects.

Add play-services-libs as project. enter image description here

And Add library in build path.

enter image description here

GrIsHu
  • 29,068
  • 10
  • 64
  • 102
  • I tried but it's giving an error "Type mismatch: cannot convert from SupportMapFragment to GoogleMap" – user3326455 Feb 19 '14 at 05:33
  • Try to clean your project and then check. Make sure you have added the library `android-support-v4.jar` in your project's build path. – GrIsHu Feb 19 '14 at 05:34
  • I Cleaned, now it's showing "Open Declaration com.google.android.gms.maps.SupportMapFragment Note: This element neither has attached source nor attached Javadoc and hence no Javadoc could be found. " – user3326455 Feb 19 '14 at 05:36
  • Is your jar file inside your projects libs folder ? – GrIsHu Feb 19 '14 at 05:41
  • Add this lines `` in your manifest file inside `` tag. – GrIsHu Feb 19 '14 at 05:44
  • are you talking about `Google play service`?? here is a pic ..http://postimg.org/image/ok101s8kt/ it is into `Reference Library` – user3326455 Feb 19 '14 at 05:45
  • Noopp i am talking about the `android-support-v4.jar` file. which should be in your libs folder. – GrIsHu Feb 19 '14 at 05:48
  • `android-support-v4.jar` is inside `Android Private Libraries` and your Manifest file i tried this but still not responding.. – user3326455 Feb 19 '14 at 05:50
  • @user3326455 Please update your question with your latest error. – GrIsHu Feb 19 '14 at 06:00
  • Unfortunately, maps has stopped. – user3326455 Feb 19 '14 at 06:01
  • Try out to get your map using the code `googleMap = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map).getMap();` @user3326455 It should work now. If doesn't then update your question with latest error. – GrIsHu Feb 19 '14 at 06:01
  • Is there a `google-play-services_lib.jar` added in your project ? – GrIsHu Feb 19 '14 at 06:18
  • i added `Google-play-services` **project->properties->java build path->Libraries->add external library(went to sdk path extras->google(folder)->google_play_services\libproject\google-play-services_lib‌​\libs) then added this library...** i followed that instruction to import Google-play-services!! – user3326455 Feb 19 '14 at 06:22
  • That library should be copied into your workspace. Otherwise it will not properly reference it. See my updated answer. – GrIsHu Feb 19 '14 at 06:24
  • Yeah i got it after Vogella tutorial ....while i added it not through your process...But when i import it through "Import" ..it shows nothing...help! – user3326455 Feb 19 '14 at 06:30
  • What are you saying? @user3326455 I didn't get you. – GrIsHu Feb 19 '14 at 06:35
  • You were right i hadn't imported successfully, I'm learning it from youtube....thanks for paying time :) – user3326455 Feb 19 '14 at 08:45
  • You're Welcome !! :) Glad that helped you. All the Best :) – GrIsHu Feb 19 '14 at 08:46
0

If you want to run Google map in emulator see this step by step process which I answered in this previous question

Community
  • 1
  • 1
Shailendra Madda
  • 20,649
  • 15
  • 100
  • 138
0

First change in xml change this line

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

to

class="com.google.android.gms.maps.SupportMapFragment"

2nd change in manifest add this inside application tag

<meta-data
     android:name="com.google.android.gms.version"
     android:value="@integer/google_play_services_version" />

Most important u have add google-play-sevice-lib into ur project like this

enter image description here check ur API-Key is generated in Google console with ur computer's SHA-1;ur package name

EDIT :

How to import the google_play_services_lib Make Sure ur project and library present in same worksapce

Community
  • 1
  • 1
Kaushik
  • 6,150
  • 5
  • 39
  • 54
  • I added `google-play-sevice-lib` inside `Reference Library` because when i import it like you ..it shows nothing after pressing "Add" as you prvided a pic – user3326455 Feb 19 '14 at 05:56
  • @user3326455 : make sure when u importing `play-service-lib` u copied that into `same workspace` after that add that library into `ur project` – Kaushik Feb 19 '14 at 06:03
  • i added `Google-play-services` **project->properties->java build path->Libraries->add external library(went to sdk path extras->google(folder)->google_play_services\libproject\google-play-services_lib\libs) then added this library...** i followed that instruction to import `Google-play-services`!! – user3326455 Feb 19 '14 at 06:16
  • not like that u have to import `whole project` into eclipse and `don't forget to check the copy projects into workspace` then add that as library into ur project – Kaushik Feb 19 '14 at 07:06
0

the sure shot solved answer for unfortunately the app stopped error during implementing google play services api are:

main Activity:

import com.google.android.gms.location.LocationListener;

instead of

 import android.location.LocationListener;

use these in dependencies:(build gradle file)

    compile 'com.android.support:appcompat-v7:21.0.3'
    compile 'com.android.support:support-v4:23.0.1'
    compile 'com.google.android.gms:play-services:11.0.1'
    compile 'com.android.support:multidex:1.0.0'

Android manifest file:

  <meta-data
        android:name="com.google.android.geo.API_KEY"
        android:value="@string/google_maps_key" />

   <meta-data android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />
GeralexGR
  • 2,973
  • 6
  • 24
  • 33
ABHILASHA GUPTA
  • 141
  • 1
  • 2