I know this question has been asked many times here, but none of the solutions provided stopped my app from crashing.
Here is my code from the MainActivity:
package com.example.gpstracking2;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
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.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.Marker;
public class MainActivity extends FragmentActivity {
GoogleMap googleMap;
Marker marker = null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
Here is the code from the activity_main.xml from the layout folder:
<?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"
xmlns:map="http://schemas.android.com/apk/res-auto"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Here is the manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.gpstracking2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission android:name="com.example.gpstracking2.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="com.example.gpstracking2.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" />
<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.gpstracking2.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="KEY"/>
</application>
</manifest>
And here is the logcat:
10-06 16:57:27.966: W/dalvikvm(6735): VFY: unable to resolve static field 1346 (MapAttrs) in Lcom/google/android/gms/R$styleable;
10-06 16:57:27.966: D/dalvikvm(6735): VFY: replacing opcode 0x62 at 0x000e
10-06 16:57:27.966: D/AndroidRuntime(6735): Shutting down VM
10-06 16:57:27.966: W/dalvikvm(6735): threadid=1: thread exiting with uncaught exception (group=0x41df3700)
10-06 16:57:27.966: E/AndroidRuntime(6735): FATAL EXCEPTION: main
10-06 16:57:27.966: E/AndroidRuntime(6735): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
10-06 16:57:27.966: E/AndroidRuntime(6735): at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
10-06 16:57:27.966: E/AndroidRuntime(6735): at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:284)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
10-06 16:57:27.966: E/AndroidRuntime(6735): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:267)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.app.Activity.setContentView(Activity.java:1895)
10-06 16:57:27.966: E/AndroidRuntime(6735): at com.example.gpstracking2.MainActivity.onCreate(MainActivity.java:25)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.app.Activity.performCreate(Activity.java:5133)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.app.ActivityThread.access$600(ActivityThread.java:141)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.os.Handler.dispatchMessage(Handler.java:99)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.os.Looper.loop(Looper.java:137)
10-06 16:57:27.966: E/AndroidRuntime(6735): at android.app.ActivityThread.main(ActivityThread.java:5103)
10-06 16:57:27.966: E/AndroidRuntime(6735): at java.lang.reflect.Method.invokeNative(Native Method)
10-06 16:57:27.966: E/AndroidRuntime(6735): at java.lang.reflect.Method.invoke(Method.java:525)
10-06 16:57:27.966: E/AndroidRuntime(6735): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
10-06 16:57:27.966: E/AndroidRuntime(6735): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
10-06 16:57:27.966: E/AndroidRuntime(6735): at dalvik.system.NativeStart.main(Native Method)
10-06 16:57:27.976: W/ActivityManager(428): Force finishing activity com.example.gpstracking2/.MainActivity
10-06 16:57:28.056: D/dalvikvm(428): GC_FOR_ALLOC freed 2309K, 20% free 17147K/21256K, paused 68ms, total 68ms
10-06 16:57:28.566: W/ActivityManager(428): Activity pause timeout for ActivityRecord{42889d90 u0 com.example.gpstracking2/.MainActivity}
10-06 16:57:28.616: I/ActivityManager(428): No longer want com.android.defcontainer (pid 5432): empty #17
10-06 16:57:29.876: I/Process(6735): Sending signal. PID: 6735 SIG: 9
10-06 16:57:29.876: I/ActivityManager(428): Process com.example.gpstracking2 (pid 6735) has died.
10-06 16:57:29.896: W/InputMethodManagerService(428): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy#4266be70 attribute=null, token = android.os.BinderProxy#425f0da8
library is not added properly..
check project -> right click on properties -.java build path -order and exprot select googleplayservices library.
My code is working in way of edited as like as below and importing google library,
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
Related
I just created a simple hello world program, all codes are fine it seems, but something makes the android to show "unfortunately app needs to close" error
the startingPoint.java code which is the launcher class
package demo4;
import com.example.demo4.R;
import android.app.Activity;
import android.os.Bundle;
public class startingPoint extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
the main.xml which is the layout for launcher class
<?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" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</LinearLayout>
the androidmanifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.demo4"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="9" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".startingPoint"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
and this is the logcat
08-30 12:46:22.921: D/AndroidRuntime(326): Shutting down VM
08-30 12:46:22.941: W/dalvikvm(326): threadid=1: thread exiting with uncaught exception (group=0x40015560)
08-30 12:46:23.021: E/AndroidRuntime(326): FATAL EXCEPTION: main
08-30 12:46:23.021: E/AndroidRuntime(326): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.demo4/com.example.demo4.startingPoint}: java.lang.ClassNotFoundException: com.example.demo4.startingPoint in loader dalvik.system.PathClassLoader[/data/app/com.example.demo4-2.apk]
08-30 12:46:23.021: E/AndroidRuntime(326): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1569)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.os.Handler.dispatchMessage(Handler.java:99)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.os.Looper.loop(Looper.java:123)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.app.ActivityThread.main(ActivityThread.java:3683)
08-30 12:46:23.021: E/AndroidRuntime(326): at java.lang.reflect.Method.invokeNative(Native Method)
08-30 12:46:23.021: E/AndroidRuntime(326): at java.lang.reflect.Method.invoke(Method.java:507)
08-30 12:46:23.021: E/AndroidRuntime(326): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
08-30 12:46:23.021: E/AndroidRuntime(326): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
08-30 12:46:23.021: E/AndroidRuntime(326): at dalvik.system.NativeStart.main(Native Method)
08-30 12:46:23.021: E/AndroidRuntime(326): Caused by: java.lang.ClassNotFoundException: com.example.demo4.startingPoint in loader dalvik.system.PathClassLoader[/data/app/com.example.demo4-2.apk]
08-30 12:46:23.021: E/AndroidRuntime(326): at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:240)
08-30 12:46:23.021: E/AndroidRuntime(326): at java.lang.ClassLoader.loadClass(ClassLoader.java:551)
08-30 12:46:23.021: E/AndroidRuntime(326): at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.app.Instrumentation.newActivity(Instrumentation.java:1021)
08-30 12:46:23.021: E/AndroidRuntime(326): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1561)
08-30 12:46:23.021: E/AndroidRuntime(326): ... 11 more
So I post my comment as an answer :)
It seems that android try to find the class in your package com.example.demo4.startingPoint, but in your code the package is just demo4. Try to change the first line by package com.example.demo4.
Resloved...it was as indicated by Mtoypc. the package name was different and it was not reflected in the startingPoint.java
I want to start the navigation drawer activity when pressing a button.
Here's my code:-
public void logdinScreen(View view) {
codeM = (EditText)findViewById(R.id.editText2);
if(codeM.getText().toString().equals("0000"))
{
//Toast.makeText(getBaseContext(),"LogedIn",Toast.LENGTH_LONG).show();
Intent intent2 = new Intent(OTPScreen.this,HomeScreen.class);
startActivity(intent2);
}
}
Android Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.harpreet.btp_project" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".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>
<activity
android:name=".OTPScreen"
android:label="#string/title_activity_otpscreen" >
</activity>
<activity
android:name=".HomeScreen"
android:label="#string/title_activity_home_screen" >
</activity>
</application>
</manifest>
logcat:-
05-23 01:08:23.999 3326-3326/? D/dalvikvm﹕ Late-enabling CheckJNI
05-23 01:08:24.059 3326-3326/? E/Trace﹕ error opening trace file: No such file or directory (2)
05-23 01:08:24.059 3326-3326/? D/ActivityThread﹕ setTargetHeapUtilization:0.25
05-23 01:08:24.059 3326-3326/? D/ActivityThread﹕ setTargetHeapIdealFree:8388608
05-23 01:08:24.059 3326-3326/com.example.harpreet.btp_project D/ActivityThread﹕ setTargetHeapConcurrentStart:2097152
05-23 01:08:24.239 3326-3326/com.example.harpreet.btp_project D/dalvikvm﹕ GC_FOR_ALLOC freed 70K, 35% free 12967K/19779K, paused 21ms, total 22ms
05-23 01:08:24.259 3326-3326/com.example.harpreet.btp_project I/dalvikvm-heap﹕ Grow heap (frag case) to 29.330MB for 8294416-byte allocation
05-23 01:08:24.289 3326-3328/com.example.harpreet.btp_project D/dalvikvm﹕ GC_CONCURRENT freed 1K, 25% free 21066K/27911K, paused 12ms+1ms, total 35ms
05-23 01:08:24.429 3326-3326/com.example.harpreet.btp_project D/libEGL﹕ loaded /system/lib/egl/libEGL_adreno200.so
05-23 01:08:24.449 3326-3326/com.example.harpreet.btp_project D/libEGL﹕ loaded /system/lib/egl/libGLESv1_CM_adreno200.so
05-23 01:08:24.459 3326-3326/com.example.harpreet.btp_project D/libEGL﹕ loaded /system/lib/egl/libGLESv2_adreno200.so
05-23 01:08:24.469 3326-3326/com.example.harpreet.btp_project I/Adreno200-EGL﹕ <qeglDrvAPI_eglInitialize:299>: EGL 1.4 QUALCOMM build: (Merge)
Build Date: 07/09/13 Tue
Local Branch: AU_41
Remote Branch:
Local Patches:
Reconstruct Branch:
05-23 01:08:24.529 3326-3326/com.example.harpreet.btp_project D/OpenGLRenderer﹕ Enabling debug mode 0
05-23 01:08:39.009 3326-3326/com.example.harpreet.btp_project D/AndroidRuntime﹕ Shutting down VM
05-23 01:08:39.009 3326-3326/com.example.harpreet.btp_project W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x413e2378)
05-23 01:08:39.029 3326-3326/com.example.harpreet.btp_project E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.harpreet.btp_project/com.example.harpreet.btp_project.HomeScreen}: android.view.InflateException: Binary XML file line #19: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2071)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:4787)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #19: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
at com.example.harpreet.btp_project.HomeScreen.onCreate(HomeScreen.java:39)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2035)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:4787)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.example.harpreet.btp_project.NavigationDrawerFragment.onCreateView(NavigationDrawerFragment.java:100)
at android.support.v4.app.Fragment.performCreateView(Fragment.java:1789)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:924)
at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1116)
at android.support.v4.app.FragmentManagerImpl.addFragment(FragmentManager.java:1218)
at android.support.v4.app.FragmentManagerImpl.onCreateView(FragmentManager.java:2170)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:300)
at android.support.v7.app.AppCompatDelegateImplV7.callActivityOnCreateView(AppCompatDelegateImplV7.java:816)
at android.support.v7.app.AppCompatDelegateImplV11.callActivityOnCreateView(AppCompatDelegateImplV11.java:72)
at android.support.v7.app.AppCompatDelegateImplV7.onCreateView(AppCompatDelegateImplV7.java:804)
at android.support.v4.view.LayoutInflaterCompatHC$FactoryWrapperHC.onCreateView(LayoutInflaterCompatHC.java:44)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:675)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at android.support.v7.app.AppCompatDelegateImplV7.setContentView(AppCompatDelegateImplV7.java:249)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:106)
at com.example.harpreet.btp_project.HomeScreen.onCreate(HomeScreen.java:39)
at android.app.Activity.performCreate(Activity.java:5008)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2035)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2096)
at android.app.ActivityThread.access$600(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1207)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:213)
at android.app.ActivityThread.main(ActivityThread.java:4787)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:556)
at dalvik.system.NativeStart.main(Native Method)
The app is working untill i press that button. When i comment the intent part and uncomment the Toast part, it is working perfect.
Am i doing it wrong?
i want to deploy google maps into my android application. i followed a step-by-step procedure which i found it here. But when i run the application. I got "Unfortunately your application has stopped error. I followed each step in that document. please let me know the error.
here is my logcat's output
04-18 12:15:30.416: I/Process(1423): Sending signal. PID: 1423 SIG: 9
04-18 12:15:31.676: W/dalvikvm(1443): VFY: unable to resolve static field 2529 (MapAttrs) in Lcom/google/android/gms/R$styleable;
04-18 12:15:31.676: D/dalvikvm(1443): VFY: replacing opcode 0x62 at 0x000e
04-18 12:15:31.686: D/AndroidRuntime(1443): Shutting down VM
04-18 12:15:31.686: W/dalvikvm(1443): threadid=1: thread exiting with uncaught exception (group=0xb1a6cba8)
04-18 12:15:31.726: E/AndroidRuntime(1443): FATAL EXCEPTION: main
04-18 12:15:31.726: E/AndroidRuntime(1443): Process: tarun.ksr.mymap, PID: 1443
04-18 12:15:31.726: E/AndroidRuntime(1443): java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
04-18 12:15:31.726: E/AndroidRuntime(1443): at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
04-18 12:15:31.726: E/AndroidRuntime(1443): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.app.Activity.onCreateView(Activity.java:4785)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
04-18 12:15:31.726: E/AndroidRuntime(1443): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.app.Activity.setContentView(Activity.java:1929)
04-18 12:15:31.726: E/AndroidRuntime(1443): at tarun.ksr.mymap.MainActivity.onCreate(MainActivity.java:20)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.app.Activity.performCreate(Activity.java:5231)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2159)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.app.ActivityThread.access$800(ActivityThread.java:135)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.os.Handler.dispatchMessage(Handler.java:102)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.os.Looper.loop(Looper.java:136)
04-18 12:15:31.726: E/AndroidRuntime(1443): at android.app.ActivityThread.main(ActivityThread.java:5017)
04-18 12:15:31.726: E/AndroidRuntime(1443): at java.lang.reflect.Method.invokeNative(Native Method)
04-18 12:15:31.726: E/AndroidRuntime(1443): at java.lang.reflect.Method.invoke(Method.java:515)
04-18 12:15:31.726: E/AndroidRuntime(1443): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
04-18 12:15:31.726: E/AndroidRuntime(1443): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
04-18 12:15:31.726: E/AndroidRuntime(1443): at dalvik.system.NativeStart.main(Native Method)
04-18 12:15:34.846: I/Process(1443): Sending signal. PID: 1443 SIG: 9
Here is my MainActivity.java
package tarun.ksr.mymap;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
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 Activity {
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
final LatLng CIU = new LatLng(35.21843892856462, 33.41662287712097);
Marker ciu = mMap.addMarker(new MarkerOptions().position(CIU).title("My Office"));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
MANIFEST :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="tarun.ksr.mymap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<permission
android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" >
</permission>
<uses-permission android:name="com.example.androidmapsv2.permission.MAPS_RECEIVE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<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" >
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCfVTb5mW1c-q8RdBtX7NJJ0S1KXgkHUP0"/>
<activity
android:name="tarun.ksr.mymap.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>
</application>
Add this to the manifest-
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Also check whether the Google Play Services SDK is configured correctly.
https://developers.google.com/maps/documentation/android/start#getting_the_google_maps_android_api_v2
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
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.
And Add library in build path.
If you want to run Google map in emulator see this step by step process which I answered in this previous question
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
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
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" />
I am developing a simple Android app which uses the Google Maps API,
I had registered with Google for the API key and added it to my app but I am getting an error:
FATAL EXCEPTION: main
Process: com.s56.maps, PID: 866
12-17 09:28:56.070: E/AndroidRuntime(866): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.s56.maps/com.s56.maps.MainActivity}: android.view.InflateException: Binary XML file line #15: Error inflating class fragment
12-17 09:28:56.070: E/AndroidRuntime(866): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2176)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.app.ActivityThread.access$700(ActivityThread.java:135)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.os.Handler.dispatchMessage(Handler.java:102)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.os.Looper.loop(Looper.java:137)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.app.ActivityThread.main(ActivityThread.java:4998)
12-17 09:28:56.070: E/AndroidRuntime(866): at java.lang.reflect.Method.invokeNative(Native Method)
12-17 09:28:56.070: E/AndroidRuntime(866): at java.lang.reflect.Method.invoke(Method.java:515)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
12-17 09:28:56.070: E/AndroidRuntime(866): at dalvik.system.NativeStart.main(Native Method)
12-17 09:28:56.070: E/AndroidRuntime(866): Caused by: android.view.InflateException: Binary XML file line #15: Error inflating class fragment
12-17 09:28:56.070: E/AndroidRuntime(866): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.view.LayoutInflater.inflate(LayoutInflater.java:397)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.view.LayoutInflater.inflate(LayoutInflater.java:353)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:290)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.app.Activity.setContentView(Activity.java:1928)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.s56.maps.MainActivity.onCreate(MainActivity.java:19)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.app.Activity.performCreate(Activity.java:5243)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2140)
12-17 09:28:56.070: E/AndroidRuntime(866): ... 11 more
***12-17 09:28:56.070: E/AndroidRuntime(866): Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml does not have the right value. Expected 4030500 but found 0. You must have the following declaration within the <application> element: <meta-data android:name="com.google.android.gms.version" android:value="#integer/google_play_services_version" />***
12-17 09:28:56.070: E/AndroidRuntime(866): at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.google.android.gms.maps.internal.q.v(Unknown Source)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.google.android.gms.maps.internal.q.u(Unknown Source)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.google.android.gms.maps.MapFragment$b.cE(Unknown Source)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.google.android.gms.dynamic.a.a(Unknown Source)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
12-17 09:28:56.070: E/AndroidRuntime(866): at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.app.Activity.onCreateView(Activity.java:4784)
12-17 09:28:56.070: E/AndroidRuntime(866): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
12-17 09:28:56.070: E/AndroidRuntime(866): ... 21 more
And my XML file is
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.s56.maps"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
/>
<permission
android:name="com.s56.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature"></permission>
<uses-permission
android:name="com.s56.maps.permission.MAPS_RECEIVE"/>
<uses-permission
android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission
android:name="android.permission.INTERNET"/>
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<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.s56.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="A***MY_API_KEY***M"/>
</application>
</manifest>
and my activity_main.xml has
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment"/>
And my main class i.e activity class has,
public class MainActivity extends Activity
{
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mMap=
((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
final LatLng CIU = new LatLng(17.426944259701596, 78.5340459823017);
Marker c = mMap.addMarker(new MarkerOptions()
.position(CIU).title("s56 labs"));
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }
I had added Google Play services as library to Eclipse work space.
Kindly help me with this, and I am new to Android.
You must add this to your AndroidManifest.xml:
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />