I am trying to make a simple app that shows google maps on my device. I run it in my Alcatel OT 990 android device (v. 2.2.2) but it shows the error message “Application has stopped unexpectedly…. then force close”. I believe I’m doing everything right, since i follow the instructions from a youtube tutorial that works.
This is my code (I’ ve included Android Support Library, Google Play Services Library and android.jar):
Manifest
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.xristina.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.xristina.maps.permission.MAPS_RECEIVE"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<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.tutorialgooglemaps.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="*************my key here*********************"/>
</application>
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 xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
MainActivity.java
package com.xristina.maps;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.os.Bundle;
import android.view.Menu;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends android.support.v4.app.FragmentActivity {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setUpMapIfNeeded();
}
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
if (mMap == null) {
mMap = ((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(0, 0)).title("Marker"));
}
}
Any ideas please??
Ι added the code suggested by @BBonDoo and the logcat result was:
02-06 16:59:34.807: W/dalvikvm(2735): threadid=1: thread exiting with uncaught exception (group=0x400207d8)
02-06 16:59:34.817: E/AndroidRuntime(2735): FATAL EXCEPTION: main
02-06 16:59:34.817: E/AndroidRuntime(2735): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.xristina.maps/com.example.tutorialgooglemaps.MainActivity}: java.lang.ClassNotFoundException: com.example.tutorialgooglemaps.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.xristina.maps-2.apk]
02-06 16:59:34.817: E/AndroidRuntime(2735): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2603)
02-06 16:59:34.817: E/AndroidRuntime(2735): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2697)
02-06 16:59:34.817: E/AndroidRuntime(2735): at android.app.ActivityThread.access$2300(ActivityThread.java:126)
02-06 16:59:34.817: E/AndroidRuntime(2735): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2051)
02-06 16:59:34.817: E/AndroidRuntime(2735): at android.os.Handler.dispatchMessage(Handler.java:99)
02-06 16:59:34.817: E/AndroidRuntime(2735): at android.os.Looper.loop(Looper.java:123)
02-06 16:59:34.817: E/AndroidRuntime(2735): at android.app.ActivityThread.main(ActivityThread.java:4645)
02-06 16:59:34.817: E/AndroidRuntime(2735): at java.lang.reflect.Method.invokeNative(Native Method)
02-06 16:59:34.817: E/AndroidRuntime(2735): at java.lang.reflect.Method.invoke(Method.java:521)
02-06 16:59:34.817: E/AndroidRuntime(2735): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
02-06 16:59:34.817: E/AndroidRuntime(2735): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
02-06 16:59:34.817: E/AndroidRuntime(2735): at dalvik.system.NativeStart.main(Native Method)
02-06 16:59:34.817: E/AndroidRuntime(2735): Caused by: java.lang.ClassNotFoundException: com.example.tutorialgooglemaps.MainActivity in loader dalvik.system.PathClassLoader[/data/app/com.xristina.maps-2.apk]
02-06 16:59:34.817: E/AndroidRuntime(2735): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
02-06 16:59:34.817: E/AndroidRuntime(2735): at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
02-06 16:59:34.817: E/AndroidRuntime(2735): at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
02-06 16:59:34.817: E/AndroidRuntime(2735): at android.app.Instrumentation.newActivity(Instrumentation.java:1022)
02-06 16:59:34.817: E/AndroidRuntime(2735): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2595)
02-06 16:59:34.817: E/AndroidRuntime(2735): ... 11 more
I also have to say that this code wasn’t included in the tutorial i studied at
http://www.youtube.com/watch?v=mRnEkP2q4fo and http://www.youtube.com/watch?v=OZRgiwGfvSQ
[Answer new ]…added update]
Your Logcat is good. It means as follows;
Please look into two pictures and match your package name(①) with the correct one(②).
Please replace the package name in the manifest file with the package name in your java file.
It is correct code in your manifest file;
[Answer old]
You did not finish writing the code enough to display Google Maps in your MainActivity.java. Please fill your code with the code as shown in the below, which is the basic code you must know essentially in order to display the Google Maps in Android platform: