ClassNotFoundException: com.google.android.gms.maps.MapFragment with AndroidStudio - android

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.

Related

Run Amazon device messaging on android virtual device

I have bug with amazon device messaging.
compile in gradle:
//compile in gradle
provided files('libs/amazon-device-messaging-1.0.1.jar')
I've been tried:
compile files('libs/amazon-device-messaging-1.0.1.jar')
manifest:
<permission android:name="com.bookmark.money.permission.RECEIVE_ADM_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.bookmark.money.permission.RECEIVE_ADM_MESSAGE" />
<uses-permission android:name="com.amazon.device.messaging.permission.RECEIVE" />
<application ...>
<amazon:enable-feature
android:name="com.amazon.device.messaging"
android:required="true" />
</application>
call ADM:
//call adm
ADM adm = new ADM(context); //error inline
in logcat:
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.amazon.device.messaging.ADM
at com.zoostudio.moneylover.cloudMessage.CloudMessageHelper.getCloudMessageId(CloudMessageHelper.java:21)
at com.zoostudio.moneylover.cloudMessage.CloudMessageHelper.register(CloudMessageHelper.java:14)
at com.zoostudio.moneylover.MoneyApplication.createObjectSingleton(MoneyApplication.java:511)
at com.zoostudio.moneylover.MoneyApplication.onCreate(MoneyApplication.java:294)
at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1000)
at android.app.ActivityThread.handleBindApplication(ActivityThread.java:4391)
at android.app.ActivityThread.access$1300(ActivityThread.java:141)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1294)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5041)
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:793)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
at dalvik.system.NativeStart.main(Native Method)'
Please help me if you have any ideas!
*Update:
Levon from Amazon reply for me. ADM can run on physical device (of Amazon or not) but not work :(
same error:
java.lang.NoClassDefFoundError: Failed resolution of: Lcom/amazon/device/messaging/ADM;
I have had the same issue. Problem was in xml namespace in manifest.
It should be like in documentation:
xmlns:amazon="http://schemas.amazon.com/apk/res/android"​

SupportMapFragment not found

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

Google Play Service library and Google Maps

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.

Android Google Maps Activity won't start

I'm working on an Android app that should start a MapView when a tour is selected from a list. However The app seems to crash everytime I try to open this MapView via an Intent...
Here is my code:
MainActivity.java:
public class MainActivity extends Activity {
public final static String SELECTED_TOUR = "com.me.tourapp.TOUR";
public static TourListAdapter tourListAdapter;
private static int selectedTour;
#Override
protected void onCreate(Bundle savedInstanceState) {
...
}
public void startTour(View view) {
Intent intent = new Intent(view.getContext(), TourMapActivity.class);
intent.putExtra(SELECTED_TOUR, selectedTour);
startActivity(intent);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
...
}
}
TourMapActivity.java:
public class TourMapActivity extends Activity {
#SuppressLint("NewApi")
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tour_map);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
getActionBar().setDisplayHomeAsUpEnabled(true);
}
//check if tour is passed via intent (test):
Intent intent = getIntent();
int tourIndex = Integer.parseInt(intent.getStringExtra(MainActivity.SELECTED_TOUR));
Toast.makeText(getApplicationContext(), "the tour: "+ tourIndex, Toast.LENGTH_LONG).show();
}
}
activity_tour_map.xml:
<?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:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.MapFragment" />
</LinearLayout>
and some snippets from the manifest:
<permission
android:name="com.me.tourapp.permission.MAPS_RECEIVE"
android:protectionLevel="signature"/>
<uses-permission android:name="com.me.tourapp.permission.MAPS_RECEIVE"/>
<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"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-library android:name="com.google.android.maps" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyBqs_*****"/>
I also included android-support-v4.jar to the java build path and installed and imported the google play services...
I just don't hava a clue where I'm making the errors...
edit:
I added the logcat:
E/AndroidRuntime(28248): FATAL EXCEPTION: main
E/AndroidRuntime(28248): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.hansvn.plaktour/com.hansvn.plaktour.TourMapActivity}: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
E/AndroidRuntime(28248): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2100)
E/AndroidRuntime(28248): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2125)
E/AndroidRuntime(28248): at android.app.ActivityThread.access$600(ActivityThread.java:140)
E/AndroidRuntime(28248): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1227)
E/AndroidRuntime(28248): at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime(28248): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime(28248): at android.app.ActivityThread.main(ActivityThread.java:4898)
E/AndroidRuntime(28248): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime(28248): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime(28248): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1006)
E/AndroidRuntime(28248): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:773)
E/AndroidRuntime(28248): at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime(28248): Caused by: android.view.InflateException: Binary XML file line #7: Error inflating class fragment
E/AndroidRuntime(28248): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
E/AndroidRuntime(28248): at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
E/AndroidRuntime(28248): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
E/AndroidRuntime(28248): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
E/AndroidRuntime(28248): at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
E/AndroidRuntime(28248): at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:308)
E/AndroidRuntime(28248): at android.app.Activity.setContentView(Activity.java:1924)
E/AndroidRuntime(28248): at com.hansvn.plaktour.TourMapActivity.onCreate(TourMapActivity.java:16)
E/AndroidRuntime(28248): at android.app.Activity.performCreate(Activity.java:5206)
E/AndroidRuntime(28248): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1083)
E/AndroidRuntime(28248): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2064)
E/AndroidRuntime(28248): ... 11 more
E/AndroidRuntime(28248): 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
E/AndroidRuntime(28248): at android.support.v4.app.Fragment.instantiate(Fragment.java:401)
E/AndroidRuntime(28248): at android.support.v4.app.Fragment.instantiate(Fragment.java:369)
E/AndroidRuntime(28248): at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:272)
E/AndroidRuntime(28248): at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
E/AndroidRuntime(28248): ... 21 more
E/AndroidRuntime(28248): Caused by: java.lang.ClassNotFoundException: com.google.android.gms.maps.SupportMapFragment
E/AndroidRuntime(28248): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
E/AndroidRuntime(28248): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
E/AndroidRuntime(28248): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
E/AndroidRuntime(28248): at android.support.v4.app.Fragment.instantiate(Fragment.java:391)
E/AndroidRuntime(28248): ... 24 more
You messing API V2 with API V1 of Google Maps. So first of all decide which API are you going to use.
Next, if you have decided that you are using API V2 (as it looks by most of your code), then remove this line:
<uses-library android:name="com.google.android.maps" />
It's part of API V1 and doesn't need to be in V2.
Second thing you need to decide is what is the minAPI level of your application. If you are writing your application to API level < 11 then you should use SupportMapFragment in your XML, like this:
<?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:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
and your activity should extend FragmentActivity, this is the case were you should use
the google-support-v4 package, because FragmentActivity is part of this package.
UPDATE:
From your logcat output:
Caused by: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.me.tourapp/com.me.tourapp.TourMapActivity}; have you declared this activity in your AndroidManifest.xml?
which means you have not declared your Activity TourMapActivity in the manifest file, and this is the reason for your error.
UPDATE2:
this error:
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.
derived as said in the error from the fact that SupportMapFragment class was not found.
what means that you haven't reference the google-play-services library the right way because this class is part of this library. please read the first 3 steps of this blog post I wrote on how to reference it correctly:
Google Map API V2

"Error inflating class fragment" with google map

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{
... }

Categories

Resources