I tried to make a sample project using Google Map, but I couldn't.
Help me please!
Test Device : Android 4.0.4
Error Message :
12-29 23:45:32.605: E/AndroidRuntime(9437): FATAL EXCEPTION: main
12-29 23:45:32.605: E/AndroidRuntime(9437):
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.test_googlemap/com.example.test_googlemap.MainActivity}:
android.view.InflateException: Binary XML file line #2: Error
inflating class fragment 12-29 23:45:32.605: E/AndroidRuntime(9437):
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1968)
12-29 23:45:32.605: E/AndroidRuntime(9437): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1993)
12-29 23:45:32.605: E/AndroidRuntime(9437): at
android.app.ActivityThread.access$600(ActivityThread.java:127) 12-29
23:45:32.605: E/AndroidRuntime(9437): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1159)
12-29 23:45:32.605: E/AndroidRuntime(9437): at
android.os.Handler.dispatchMessage(Handler.java:99) 12-29
23:45:32.605: E/AndroidRuntime(9437): at
android.os.Looper.loop(Looper.java:137) 12-29 23:45:32.605:
E/AndroidRuntime(9437): at
android.app.ActivityThread.main(ActivityThread.java:4507) 12-29
23:45:32.605: E/AndroidRuntime(9437): at
java.lang.reflect.Method.invokeNative(Native Method) 12-29
23:45:32.605: E/AndroidRuntime(9437): at
java.lang.reflect.Method.invoke(Method.java:511) 12-29 23:45:32.605:
E/AndroidRuntime(9437): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:790)
12-29 23:45:32.605: E/AndroidRuntime(9437): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:557) 12-29
23:45:32.605: E/AndroidRuntime(9437): at
dalvik.system.NativeStart.main(Native Method) 12-29 23:45:32.605:
E/AndroidRuntime(9437): Caused by: android.view.InflateException:
Binary XML file line #2: Error inflating class fragment 12-29
23:45:32.605: E/AndroidRuntime(9437): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:697)
12-29 23:45:32.605: E/AndroidRuntime(9437): at
android.view.LayoutInflater.inflate(LayoutInflater.java:466) 12-29
23:45:32.605: E/AndroidRuntime(9437): at
android.view.LayoutInflater.inflate(LayoutInflater.java:396) 12-29
23:45:32.605: E/AndroidRuntime(9437): at
android.view.LayoutInflater.inflate(LayoutInflater.java:352) 12-29
23:45:32.605: E/AndroidRuntime(9437): at
com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:271)
12-29 23:45:32.605: E/AndroidRuntime(9437): at
android.app.Activity.setContentView(Activity.java:1835) 12-29
23:45:32.605: E/AndroidRuntime(9437): at
com.example.test_googlemap.MainActivity.onCreate(MainActivity.java:11)
12-29 23:45:32.605: E/AndroidRuntime(9437): at
android.app.Activity.performCreate(Activity.java:4465) 12-29
23:45:32.605: E/AndroidRuntime(9437): at
android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1052)
12-29 23:45:32.605: E/AndroidRuntime(9437): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1932)
12-29 23:45:32.605: E/AndroidRuntime(9437): ... 11 more 12-29
23:45:32.605: E/AndroidRuntime(9437): Caused by:
java.lang.ClassCastException: com.google.android.gms.maps.MapFragment
cannot be cast to android.support.v4.app.Fragment 12-29 23:45:32.605:
E/AndroidRuntime(9437): at
android.support.v4.app.Fragment.instantiate(Fragment.java:394) 12-29
23:45:32.605: E/AndroidRuntime(9437): at
android.support.v4.app.Fragment.instantiate(Fragment.java:369) 12-29
23:45:32.605: E/AndroidRuntime(9437): at
android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
12-29 23:45:32.605: E/AndroidRuntime(9437): at
android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
12-29 23:45:32.605: E/AndroidRuntime(9437): ... 20 more
Source Code :
package com.example.test_googlemap;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<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.MapFragment"/>
Manifest.xml :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test_googlemap"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="3"
android:targetSdkVersion="15" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.test_googlemap.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="I removed it!"/>
</application>
<permission
android:name="com.example.Test_GoogleMap.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.example.Test_GoogleMap.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"/>
</manifest>
You are extending FragmentActivity, indicating that you are trying to use the Android Support package backport of fragments. However, your <fragment> element refers to MapFragment, which is for the native API Level 11 edition of fragments.
Replace MapFragment with SupportMapFragment, and that should clear up this specific crash.
I had the same problem and I did the mistake to only add one of the 2 following tags.
Note that you are also missing one of these two
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="<YOUR VALUE>"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
The actual error is really misleading, as you might be thinking of some API level UI issue.
Some times you are using both -
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="<YOUR VALUE>"
/>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="<YOUR VALUE>"
/>
Make sure , Don't use both ...
if you need Location , Places and maps then use geo.API_KEY
and if you need places and maps then use maps.v2.API_KEY
Accepted answer is correct but meaningful information i share with you, may be anyone facing same issue what i face
If everything is woking same as google code then please check manifest file in my case i added geo key and map key that's why exception occurs,
Note - do not add two keys in manifest file remove map key
meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="#string/google_maps_key"/>
above code and add this code.
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="#string/auto_location"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version"/>
This problem also occurs when it is not able to inflate the Fragment class mentioned in the activity_main.xml(or the XML file present under res/layout), due to a SDK version incompatibility in the andriod_manifest.xml file.
The correct versions for SDK levels to get the map on an emulator is this:
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="21" />
Even if it's an already answered question this error can also appear if you call the super.onCreateViewin your fragment. It will crash at run time.
Be sure you overridden the onCreateView method and inflated your layout:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.my_fragment, container, false);
return view;
}
In my case, I had to do two corrections to make this exception go away.
The activity should extend FragmentActivity and not Activity
Manifest file needs a uses-permission for ACCESS_NETWORK_STATE (my file already had INTERNET permission)
This defect has been resolved in play services library v9.0.0. https://code.google.com/p/gmaps-api-issues/issues/detail?id=9021#makechanges
Use the internet permission to be direct child of manifest file.. Like below and try..
Also You should have the following for using map:
1.Should extend Map activity in your activity file
2.Should have API key i didn't see any key in your code.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.test_googlemap"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET"/>
<uses-sdk
android:minSdkVersion="3"
android:targetSdkVersion="15" />
Do u have valid Google Map API key?
try using
public class MainActivity extends MapActivity{
... }
Related
This question already has answers here:
After Google Play Service update to version 13 I got an error
(8 answers)
Closed 9 years ago.
I am trying to implement simple google maps example I searched about but not clear about the solution
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.syntel.mapexample"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<permission
android:name="com.syntel.mapexample.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.syntel.mapexample.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Required OpenGL ES 2.0. for Maps V2 -->
<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.syntel.mapexample.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="AIzaSyBllmHwXofzx3N6YpCKmkMXh7rfc4lSL_Q" />
</application>
</manifest>
XML:
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
I am trying to implement simple Map example for viewing the map but getting error
Logcat details:
02-20 10:53:15.706: E/AndroidRuntime(23385): java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.syntel.mapexample/com.syntel.mapexample.MainActivity}: android.view.InflateException: Binary
XML file line #6: Error inflating class fragment
02-20 10:53:15.706: E/AndroidRuntime(23385): at
android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2180)
02-20 10:53:15.706: E/AndroidRuntime(23385): at
android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2230)
02-20 10:53:15.706: E/AndroidRuntime(23385): at
android.app.ActivityThread.access$600(ActivityThread.java:141)
02-20 10:53:15.706: E/AndroidRuntime(23385): at
android.app.ActivityThread$H.handleMessage(ActivityThread.java:1234)
02-20 10:53:15.706: E/AndroidRuntime(23385): at android.os.Handler.dispatchMessage(Handler.java:99)
02-20 10:53:15.706: E/AndroidRuntime(23385): at android.os.Looper.loop(Looper.java:137)
02-20 10:53:15.706: E/AndroidRuntime(23385): at
android.app.ActivityThread.main(ActivityThread.java:5041)
02-20 10:53:15.706: E/AndroidRuntime(23385): at java.lang.reflect.Method.invokeNative(Native Method)
02-20 10:53:15.706: E/AndroidRuntime(23385): at java.lang.reflect.Method.invoke(Method.java:511)
02-20 10:53:15.706: E/AndroidRuntime(23385): at
com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
02-20 10:53:15.706: E/AndroidRuntime(23385): at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
02-20 10:53:15.706: E/AndroidRuntime(23385): at dalvik.system.NativeStart.main(Native Method)
02-20 10:53:15.706: E/AndroidRuntime(23385): Caused by: android.view.InflateException: Binary XML file
line #6: Error inflating class fragment
02-20 10:53:15.706: E/AndroidRuntime(23385): 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" />
Add the Google Play services version to your app's manifest
Edit your application's AndroidManifest.xml file, and add the
following declaration within the element. This embeds the version of
Google Play services that the app was compiled with.
You need to add <meta-data> under <application> tag into your AndroidManifest.xml
....<application>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
This is because latest google play services requires a version name, which is to be mentioned using <meta-data .. /> inside AndroidManifest.xml
Like the exception says:
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" />
Add it below or above the Google Maps API key
I am trying to get Google Maps Android API v2 working on Android 2.2 on a HTC Desire.
My main.xml contains the following:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dk.sw510e13.user"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="dk.sw510e13.user.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>
</manifest>
This is my activity.
package dk.sw510e13.user;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.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;
}
}
When I run the application, I will get the following exception. It seems that it cannot find SupportMapFragment, however, I believe that I have both the support library and Google Play Services as dependencies. When creating the project in Android Studio I chose to add support for fragments.
01-17 23:52:55.237 2557-2557/dk.sw510e13.user E/AndroidRuntime﹕ FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{dk.sw510e13.user/dk.sw510e13.user.MainActivity}: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2787)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2803)
at android.app.ActivityThread.access$2300(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2136)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:144)
at android.app.ActivityThread.main(ActivityThread.java:4937)
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)
Caused by: android.view.InflateException: Binary XML file line #11: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:582)
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 dk.sw510e13.user.MainActivity.onCreate(MainActivity.java:13)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1069)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2751)
... 11 more
Caused by: android.support.v4.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
at android.support.v4.app.Fragment.instantiate(Fragment.java:409)
at android.support.v4.app.Fragment.instantiate(Fragment.java:377)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:277)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:558)
... 20 more
Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment in loader dalvik.system.PathClassLoader[/data/app/dk.sw510e13.user-2.apk]
at dalvik.system.PathClassLoader.findClass(PathClassLoader.java:243)
at java.lang.ClassLoader.loadClass(ClassLoader.java:573)
at java.lang.ClassLoader.loadClass(ClassLoader.java:532)
at android.support.v4.app.Fragment.instantiate(Fragment.java:399)
... 23 more
This is what I have in my dependencies.
Can anyone tell me what I am doing wrong?
UPDATE
This is my manifest.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dk.sw510e13.user"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<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" >
<activity
android:name="dk.sw510e13.user.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="XXXXXX"/>
</application>
</manifest>
This is the problem that seems to be occurred when missing Google Play services.
I request you to please follow the steps mentioned below to get the Google Play services to be included in your application.
copying the google-play-services.jar in libs folder and set in the build path of eclipse is a wrong method.
import Google Play services in your project and add it in workspace.
from location of your SDK folder.
\extras\google\google_play_services\libproject\google-play-services_lib
2! Now you added Google Play Services to your work space, we have to create a reference
from our project to this library. Right-Click your project and choose “Properties” go
to the Android section, in the lower part press the “Add…” button and add a reference
to that library. Your result should be as in the screen shot bellow:
adding Google Play services library
Please Add
<permission
android:name="com.anchit.locationapi.maps.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
in your manifest
I'm trying to use Google maps v2 on my android App. I'm using Android Studio; I followed steps indicated here: https://developers.google.com/maps/documentation/android/start#overview
In my AndroidManifest.xml I've:
<uses-sdk
android:minSdkVersion="12"
android:targetSdkVersion="16" />
<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" />
On my build.gradle I've:
android {
compileSdkVersion 17
buildToolsVersion "17.0.0"
defaultConfig {
minSdkVersion 12
targetSdkVersion 16
}
}
dependencies {
compile 'com.android.support:support-v4:18.0.0'
compile 'com.google.android.gms:play-services:3.1.36'
}
My first Activity:
public class HomeActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.home);
}
}
My layout:
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:name="com.google.android.gms.maps.MapFragment" />
I can compile my project but when I try to deploy to my phone I've this exception:
09-03 17:28:08.604 9787-9787/? E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{it.mobile/it.mobile.HomeActivity}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2211)
at android.app.ActivityThread.access$600(ActivityThread.java:149)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1300)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:153)
at android.app.ActivityThread.main(ActivityThread.java:5086)
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:821)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:584)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:258)
at android.app.Activity.setContentView(Activity.java:1867)
at it.mobile.HomeActivity.onCreate(HomeActivity.java:12)
at android.app.Activity.performCreate(Activity.java:5020)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1080)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
... 11 more
Caused by: android.app.Fragment$InstantiationException: Unable to instantiate fragment com.google.android.gms.maps.MapFragment: make sure class name exists, is public, and has an empty constructor that is public
at android.app.Fragment.instantiate(Fragment.java:584)
at android.app.Fragment.instantiate(Fragment.java:552)
at android.app.Activity.onCreateView(Activity.java:4668)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:680)
... 20 more
Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.MapFragment
at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
at android.app.Fragment.instantiate(Fragment.java:574)
... 23 more
In the properties of the project I check export to support library and google services library.
Thanks
At the end I solved the problem recreating a new project in Android Studio. Not sure which was the problem.
I try to create a simple GoogleMap by Using Google Play Service and Google Maps API. But all the times I get errors...
I´m working with IntelliJ 12.1, here my full Code:
RecorderMap.java
package com.example.GPSApp;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
public class RecorderMap extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.map);
}
}
map.xml
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.maps.SupportMapFragment
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.GPSApp"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk
android:minSdkVersion="10"
android:targetSdkVersion="16" />
<permission
android:name="com.example.GPSApp.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.newmapview.permission.MAPS_RECEIVE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<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-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-feature android:name="android.hardware.location.gps" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application android:label="#string/app_name">
<uses-library android:name="com.google.android.maps" />
<activity android:name=".MainActivity"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".RecorderMap"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"/>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="XXX" />
</application>
</manifest>
I think the Problem is how I include the GooGlePlayService... I´ve tried to add as module, as libary as External Libary but I don't know how to include and to use it right... :(
EDIT:
LogCat
08-28 07:41:59.869: ERROR/AndroidRuntime(23080): FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.GPSApp/com.example.GPSApp.RecorderMap}: android.view.InflateException: Binary XML file line #2: Error inflating class com.google.android.gms.maps.SupportMapFragment
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1647)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
at android.app.ActivityThread.access$1500(ActivityThread.java:117)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #2: Error inflating class com.google.android.gms.maps.SupportMapFragment
at android.view.LayoutInflater.createView(LayoutInflater.java:508)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:570)
at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
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:210)
at android.app.Activity.setContentView(Activity.java:1660)
at com.example.GPSApp.RecorderMap.onCreate(RecorderMap.java:18)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
... 11 more
Caused by: java.lang.NoSuchMethodException: SupportMapFragment(Context,AttributeSet)
at java.lang.Class.getMatchingConstructor(Class.java:643)
at java.lang.Class.getConstructor(Class.java:472)
at android.view.LayoutInflater.createView(LayoutInflater.java:480)
... 20 more
****EDIT2**
Problem solved by using this: java.lang.noclassdeffounderror: com.google.android.gms.R$styleable**
The only thing I find missing in your RecorderMap.java file is that you haven't imported the SupportFragment class. So add this line to it
import com.google.android.gms.maps.SupportMapFragment;
If that doesn't work, then check out the following.
From what you are saying, it means you have already installed the google play services. If not, then try installing it using this link http://developer.android.com/google/play-services/setup.html
After that, referencing the google play services library should be as easy as editing your build.gradle file. The current version of android studio makes this possible. Under dependencies in your build.gradle file, add the following code
compile 'com.google.android.gms:play-services:3.1.36'
You seem to have your API key intact.
Finally, remember you need to test your app on an actual android device and not an emulator. The android API version 2 is not yet able to display maps on emulators.
I think this should be okay for your app to work.
I get the following error from the emulator in Eclipse when I run an Android application...
"The application has stopped unexpectedly. Please try again"
There are no error icons appearing in the project folder in Eclipse. I have already tried...
Cleaning the Project
Android Tools > Fix Project Properties
Updating the Build Path
My Error Log is saying...
"java.lang.RuntimeException: Unable to instantiate activity ComponentInfo..."
The Error Log goes onto say...
"Caused by: java.lang.ClassNotFoundException..."
Just to note that I do not have a "Build.xml" file in my project folder but instead a "apktool.yml" if this makes any difference.
Any suggestions??
EDIT:
Here's the manifest file...
<?xml version="1.0" encoding="UTF-8"?>
<manifest android:versionCode="61" android:versionName="1.2.2" package="com.__.__"
xmlns:android="http://schemas.android.com/apk/res/android">
<uses-sdk android:minSdkVersion="10" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application android:label="#string/app_name" android:icon="#drawable/ic_launcher">
<activity android:label="#string/app_name" android:name=".MTActivity" android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:label="#string/app_name" android:name=".RCActivity" android:screenOrientation="portrait" />
...
Errors generated LogCat...
E/AndroidRuntime(6220): FATAL EXCEPTION: main
E/AndroidRuntime(6220): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ir.mtools/com.ir.mtools.MTActivity}: java.lang.ClassNotFoundException:
com.irtza.pulmtools.MTActivity in loader dalvik.system.PathClassLoader[/data/app/com.ir.mtools-1.apk]
E/AndroidRuntime(6220): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1573)
E/AndroidRuntime(6220): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1667)
E/AndroidRuntime(6220): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
E/AndroidRuntime(6220): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:935)
E/AndroidRuntime(6220): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(6220): at android.os.Looper.loop(Looper.java:130)
E/AndroidRuntime(6220): at android.app.ActivityThread.main(ActivityThread.java:3687)
E/AndroidRuntime(6220): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(6220): at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime(6220): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
E/AndroidRuntime(6220): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
E/AndroidRuntime(6220): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(6220): Caused by: java.lang.ClassNotFoundException: com.ir.mtools.MTActivity in loader dalvik.system.PathClassLoader[/data/app/com.ir.mtools-1.apk]
Whenever this happens it means your application has encountered a runtime exception, which means no errors will show up at compile time. In this case I'm guessing you have not declared the activity in the AndroidManifest.xml file, but without seeing more code that's only a guess.
java.lang.ClassNotFoundException: com.ir.mtools.MTActivity
Is com.ir.mtools.MTActivity this part of some library? if so have you included it in your build path ?