0

i'm making an android map application , using goggle maps v2 , alla went ok until i run the application , it crashs . thes are my files :

MainActivity.java

package com.geo.app;

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

import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
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.Marker;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends FragmentActivity {
    static final LatLng HAMBURG = new LatLng(53.558, 9.927);
    static final LatLng KIEL = new LatLng(53.551, 9.993);
    private GoogleMap map;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        map=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map))
            .getMap();
        Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
            .title("Hamburg"));
        Marker kiel = map.addMarker(new MarkerOptions()
            .position(KIEL)
            .title("Kiel")
            .snippet("Kiel is cool")
            .icon(BitmapDescriptorFactory
                    .fromResource(R.drawable.ic_launcher)));

        // Move the camera instantly to hamburg with a zoom of 15.
        map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));

        //    Zoom in, animating the camera.
        map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
    }

}

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="match_parent"
    android:layout_height="match_parent"
    class="com.google.android.gms.maps.SupportMapFragment" />

</RelativeLayout>

Manifest.xml

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

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

<permission
    android:name="com.geo.app.permission.MAPS_RECEIVE"
    android:protectionLevel="signature" />

<uses-feature
    android:glEsVersion="0x00020000"
    android:required="true" />

<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"/>


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

</manifest> 

The application crashed , and i have this on my LogCat

   04-10 10:59:02.545  11918-11918/? D/AndroidRuntime﹕ >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
   04-10 10:59:02.545  11918-11918/? D/AndroidRuntime﹕ CheckJNI is OFF
   04-10 10:59:02.725  11918-11918/? D/AndroidRuntime﹕ --- registering native functions ---
   04-10 10:59:03.495      104-205/? I/ActivityManager﹕ Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.geo.app/.MainActivity }
   04-10 10:59:03.605  11918-11918/? D/AndroidRuntime﹕ Shutting down VM
   04-10 10:59:03.605  11918-11923/? D/dalvikvm﹕ Debugger has detached; object registry had 1 entries
   04-10 10:59:03.625  11918-11926/? I/AndroidRuntime﹕ NOTE: attach of thread 'Binder Thread #3' failed
   04-10 10:59:03.675    5325-5325/? D/PackageAddedReceiver﹕ package added com.geo.app
   04-10 10:59:03.695      104-107/? I/ActivityManager﹕ Start proc com.geo.app for activity com.geo.app/.MainActivity: pid=11928 uid=10082 gids={3003, 1015}
   04-10 10:59:04.175      182-182/? D/dalvikvm﹕ GC_EXPLICIT freed 5596 objects / 283440 bytes in 5136ms
   04-10 10:59:04.275   3332-11910/? D/RegisterService﹕ insert plugin size 1
   04-10 10:59:04.335      104-243/? D/Sensors﹕ open_akm, fd=148
   04-10 10:59:04.625        77-77/? D/AK8973﹕ Compass Start
   04-10 10:59:04.745  11928-11928/com.geo.app W/dalvikvm﹕ VFY: unable to resolve static field 3704 (MapAttrs) in Lcom/google/android/gms/R$styleable;
   04-10 10:59:04.745  11928-11928/com.geo.app D/dalvikvm﹕ VFY: replacing opcode 0x62 at 0x000e
   04-10 10:59:04.745  11928-11928/com.geo.app D/dalvikvm﹕ VFY: dead code 0x0010-00ae in Lcom/google/android/gms/maps/GoogleMapOptions;.createFromAttributes (Landroid/content/Context;Landroid/util/AttributeSet;)Lcom/google/android/gms/maps/GoogleMapOptions;
   04-10 10:59:04.755  11928-11928/com.geo.app D/AndroidRuntime﹕ Shutting down VM
   04-10 10:59:04.755  11928-11928/com.geo.app W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40028a00)
   04-10 10:59:04.775  11928-11928/com.geo.app E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
        at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
        at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
        at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:290)
        at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:558)
        at android.view.LayoutInflater.rInflate(LayoutInflater.java:618)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
        at android.view.LayoutInflater.inflate(LayoutInflater.java:276)
        at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:207)
        at android.app.Activity.setContentView(Activity.java:1654)
        at com.geo.app.MainActivity.onCreate(MainActivity.java:26)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1065)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2745)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
        at android.app.ActivityThread.access$2300(ActivityThread.java:135)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:143)
        at android.app.ActivityThread.main(ActivityThread.java:4914)
        at java.lang.reflect.Method.invokeNative(Native Method)
        at java.lang.reflect.Method.invoke(Method.java:521)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
        at dalvik.system.NativeStart.main(Native Method)
   04-10 10:59:04.845      104-244/? W/ActivityManager﹕ Force finishing activity com.geo.app/.MainActivity
3
  • post the full stacktrace. Apr 10, 2014 at 10:03
  • you need to post the full stacktrace there is a caused by part which indicates the cause of app crash. You only posted a few lines Apr 10, 2014 at 10:21
  • @Raghunandan : check it out
    – wissem46
    Apr 10, 2014 at 10:32

2 Answers 2

1

You are missing a meta tag in the manifest file

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

You don't need these

<permission
android:name="com.geo.app.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />

Also it is better to check the availability of google play services before intializing GoogleMap object

Edit:

java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable

You haven't referenced google play services library project in your android map project.

5
  • that doesn't work ,in fact this line is highlithed with red on the manifest , which means that google play version was not found ! i'm checking my libs on the android studio , to see if i linked correctly them to the project
    – wissem46
    Apr 10, 2014 at 10:25
  • @wissem46 well it should. If not the library project isn't referenced properly. Secondly post the full stacktrace. Apr 10, 2014 at 10:26
  • @wissem46 you haven't referenced google play services properly. Check the edit. Reference it properly and it will work Apr 10, 2014 at 10:34
  • 1
    @wissem46 check this developer.android.com/google/play-services/setup.html. the docs has steps for both eclipse and android studio Apr 10, 2014 at 10:43
  • Thank you @Raghunandan , that was helpful so helpful , added to that i discovered in the documentation an important detail about the android version , i was running it on a v2.2 android device , that's why the application crashed. i moved to v4.4 and wow ! it works
    – wissem46
    Apr 10, 2014 at 11:16
1

In your MainActivity.java class change the fragment import statement

import android.support.v4.app.Fragment

2
  • The import is not need Apr 10, 2014 at 10:04
  • @wissem46 there is no need for this import at all. you already have import com.google.android.gms.maps.SupportMapFragment; Apr 10, 2014 at 10:27

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.