Please help. I have tried and implemented all other solutions, but still no luck integrating google maps in my app.
The current problem is at inflating point in my fragment
05-21 00:17:24.629 26619-26619/com.wimedias12.orderr E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
at com.google.android.gms.maps.GoogleMapOptions.createFromAttributes(Unknown Source)
at com.google.android.gms.maps.SupportMapFragment.onInflate(Unknown Source)
at android.support.v4.app.FragmentActivity.onCreateView(FragmentActivity.java:279)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:676)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:749)
at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
at com.wimedias12.orderr.RestaurantFragments.RestaurantHomeFragment.onCreateView(RestaurantHomeFragment.java:66)
First thing that pops out as an answer is to reference the google services library the right way but that is set-up.
So here is my current configuration and please help me if you can.
restaurant_home.xml - my fragment layout where I want the map to be displayed
... Other fragment layout XML code ...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:id="@+id/mapMap"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp">
<fragment
android:id="@+id/mapMapppp"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</LinearLayout>
... Rest of the fragment layout XML ...
I have tried with MapView but no luck eiter, I read that using fragment is easier.
RestaurantHomeFragment.java - fragment's code
public class RestaurantHomeFragment extends SherlockFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.restaurant_home, container, false); //<-- This line breakes
....
}
This fragment is hosted in a SherlockFragmentActivity.
AndroidManifest.xml
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="14" />
<permission android:name="com.wimedias12.orderr.MAPS_RECEIVE" android:protectionLevel="signature" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="com.wimedias12.orderr.MAPS_RECEIVE" />
<uses-feature android:glEsVersion="0x00020000" android:required="true"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.VPI" >
<uses-library android:name="com.google.android.maps" />
....
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaXxXxXXXxXxxXx-WHmjbRpFz4eOqWBXdqUtQ" />
</application>
And here are my project properties, just to verify that the library well referenced.
Any help is much appreciated. Thanks!
UPDATE:
@CommonsWare answer is the right one. But because I'm using Android Studio i.e. IntelliJ Idea, I feel I need to answer how I make it work.
I just removed all references from the Project Structure window and re added one by one again, and somehow it worked, the configuration is still the same as in the image shown above. I guess IntelliJ had some problems referencing the library.
So right referencing of the library is the answer.
P.S. I ended up using MapView in a SherlockFragment. Thx for the help.
You appear to be using Android Studio or IntelliJ IDEA, and I cannot comment on that.
However, your error is normally associated with a project where you added the JAR for Google Play Services, not the entire Android library project. Here are instructions for attaching the Android library project in Eclipse or from the command line -- you will have to find the equivalent instructions for your IDE of choice.
Also note that you are presently attempting to use fragments in fragments, by having RestaurantHomeFragment
inflate a layout containing SupportMapFragment
. That is possible to do, but unless you have a strong and clear reason to do so, I wouldn't, as nested fragments add complexity.