-1

Hi I want the map inside my app... I copy three tutorial and I change key for every project and the result is " the app is stopped" I use Frangment or SupportFrangment.... Why my Samsung S4 not execute the app for see map?

Now I explain my app where I copy and change from this tutorial Premise: I load google-play-service for two times: 1- File->Import->Existing project into workspace-> google-play-services and include in every project

2-Add library google-play-services in properties of project.

Where I wrong ?? This is the manifest.xml:

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

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


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

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

    <uses-permission android:name="com.example.com.vogella.android.locationapi.maps.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" >
        <activity
            android:name="com.example.com.vogella.android.locationapi.maps.ShowMapActivity"
            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="KeyVALUE API" />
    </application>

</manifest>

This is a frangment.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=".ShowMapActivity" >

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

</RelativeLayout>

This is a ShowMapActivity.java:

    package com.example.com.vogella.android.locationapi.maps;

import android.app.Activity;
import android.os.Bundle;
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.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 ShowMapActivity extends Activity {
  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_show_map);
    map = ((MapFragment) getFragmentManager().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);
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.show_map, menu);
    return true;
  }

} 

This is the LogCat:

06-24 02:36:24.048: D/AndroidRuntime(6557): Shutting down VM
06-24 02:36:24.048: W/dalvikvm(6557): threadid=1: thread exiting with uncaught exception (group=0x418a9da0)
06-24 02:36:24.048: E/AndroidRuntime(6557): FATAL EXCEPTION: main
06-24 02:36:24.048: E/AndroidRuntime(6557): Process: com.example.com.vogella.android.locationapi.maps, PID: 6557
06-24 02:36:24.048: E/AndroidRuntime(6557): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.com.vogella.android.locationapi.maps/com.example.com.vogella.android.locationapi.maps.MainActivity}: java.lang.ClassNotFoundException: Didn't find class "com.example.com.vogella.android.locationapi.maps.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.com.vogella.android.locationapi.maps-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.com.vogella.android.locationapi.maps-1, /vendor/lib, /system/lib]]
06-24 02:36:24.048: E/AndroidRuntime(6557):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2231)
06-24 02:36:24.048: E/AndroidRuntime(6557):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
06-24 02:36:24.048: E/AndroidRuntime(6557):     at android.app.ActivityThread.access$900(ActivityThread.java:161)
06-24 02:36:24.048: E/AndroidRuntime(6557):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
06-24 02:36:24.048: E/AndroidRuntime(6557):     at android.os.Handler.dispatchMessage(Handler.java:102)
06-24 02:36:24.048: E/AndroidRuntime(6557):     at android.os.Looper.loop(Looper.java:157)
06-24 02:36:24.048: E/AndroidRuntime(6557):     at android.app.ActivityThread.main(ActivityThread.java:5356)
06-24 02:36:24.048: E/AndroidRuntime(6557):     at java.lang.reflect.Method.invokeNative(Native Method)
06-24 02:36:24.048: E/AndroidRuntime(6557):     at java.lang.reflect.Method.invoke(Method.java:515)
06-24 02:36:24.048: E/AndroidRuntime(6557):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
06-24 02:36:24.048: E/AndroidRuntime(6557):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
06-24 02:36:24.048: E/AndroidRuntime(6557):     at dalvik.system.NativeStart.main(Native Method)
06-24 02:36:24.048: E/AndroidRuntime(6557): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.com.vogella.android.locationapi.maps.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.com.vogella.android.locationapi.maps-1.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.com.vogella.android.locationapi.maps-1, /vendor/lib, /system/lib]]
06-24 02:36:24.048: E/AndroidRuntime(6557):     at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:67)
06-24 02:36:24.048: E/AndroidRuntime(6557):     at java.lang.ClassLoader.loadClass(ClassLoader.java:497)
06-24 02:36:24.048: E/AndroidRuntime(6557):     at java.lang.ClassLoader.loadClass(ClassLoader.java:457)
06-24 02:36:24.048: E/AndroidRuntime(6557):     at android.app.Instrumentation.newActivity(Instrumentation.java:1079)
06-24 02:36:24.048: E/AndroidRuntime(6557):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2222)
06-24 02:36:24.048: E/AndroidRuntime(6557):     ... 11 more

Update LOGCAT:

 06-24 03:12:05.747: D/AndroidRuntime(11752): Shutting down VM
06-24 03:12:05.747: W/dalvikvm(11752): threadid=1: thread exiting with uncaught exception (group=0x418a9da0)
06-24 03:12:05.747: E/AndroidRuntime(11752): FATAL EXCEPTION: main
06-24 03:12:05.747: E/AndroidRuntime(11752): Process: com.example.com.vogella.android.locationapi.maps, PID: 11752
06-24 03:12:05.747: E/AndroidRuntime(11752): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.com.vogella.android.locationapi.maps/com.example.com.vogella.android.locationapi.maps.ShowMapActivity}: java.lang.NullPointerException
06-24 03:12:05.747: E/AndroidRuntime(11752):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2305)
06-24 03:12:05.747: E/AndroidRuntime(11752):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2363)
06-24 03:12:05.747: E/AndroidRuntime(11752):    at android.app.ActivityThread.access$900(ActivityThread.java:161)
06-24 03:12:05.747: E/AndroidRuntime(11752):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1265)
06-24 03:12:05.747: E/AndroidRuntime(11752):    at android.os.Handler.dispatchMessage(Handler.java:102)
06-24 03:12:05.747: E/AndroidRuntime(11752):    at android.os.Looper.loop(Looper.java:157)
06-24 03:12:05.747: E/AndroidRuntime(11752):    at android.app.ActivityThread.main(ActivityThread.java:5356)
06-24 03:12:05.747: E/AndroidRuntime(11752):    at java.lang.reflect.Method.invokeNative(Native Method)
06-24 03:12:05.747: E/AndroidRuntime(11752):    at java.lang.reflect.Method.invoke(Method.java:515)
06-24 03:12:05.747: E/AndroidRuntime(11752):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1265)
06-24 03:12:05.747: E/AndroidRuntime(11752):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1081)
06-24 03:12:05.747: E/AndroidRuntime(11752):    at dalvik.system.NativeStart.main(Native Method)
06-24 03:12:05.747: E/AndroidRuntime(11752): Caused by: java.lang.NullPointerException
06-24 03:12:05.747: E/AndroidRuntime(11752):    at com.example.com.vogella.android.locationapi.maps.ShowMapActivity.onCreate(ShowMapActivity.java:26)
06-24 03:12:05.747: E/AndroidRuntime(11752):    at android.app.Activity.performCreate(Activity.java:5426)
06-24 03:12:05.747: E/AndroidRuntime(11752):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
06-24 03:12:05.747: E/AndroidRuntime(11752):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
06-24 03:12:05.747: E/AndroidRuntime(11752):    ... 11 more
Mirko Cianfarani
  • 2,023
  • 1
  • 23
  • 39

2 Answers2

1

In your AndroidManifest you have said that you will provide a class named MainActivity, however you have renamed this to ShowMapActivity, meaning that the system can't find the activity it is supposed to use

panini
  • 2,026
  • 19
  • 21
0

You need to use the newer map which is the SupportMapFragment instead of MapFragment, and use the name identifier to find the class of the SupportMapFragment.

sample:

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

<fragment
    android:id="@+id/map"
    android:name="com.androidmapsextensions.SupportMapFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent" />

</RelativeLayout>

Also you need to change the casting of map to SupportMapFragment.

SupportMapFragment map;

map = ((SupportMapFragment) getFragmentManager().findFragmentById(R.id.map))
    .getMap();
Rod_Algonquin
  • 26,074
  • 6
  • 52
  • 63