I want to load the google map API on my android. I try everything I search but it still crash.
this is my MainActivity.java
package com.example.androidmapsv2;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import com.google.android.gms.common.GooglePlayServicesUtil;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Show the Up button in the action bar.
getActionBar().setDisplayHomeAsUpEnabled(true);
GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
GoogleMap map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
}
}
This is my layout activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
This is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidmapsv2"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="16" />
<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="android.permission.INTERNET" />
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- Require OpenGL ES version 2 -->
<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" >
<uses-library android:name="com.google.android.maps" />
<activity
android:name="com.example.androidmapsv2.MainActivity"
android:label="aaa" >
<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="AIzaSyDr9xN8L3sF6W2ZRWmTR7q0lhTeOWhXEfQ" />
</application>
</manifest>
This is the key i've got
This is the libs included (Solved in update)
and i don't have a real android device, so i install it on emulator in this tutorial
This is the logcat
01-09 18:05:19.184: E/Trace(1366): error opening trace file: No such file or directory (2)
01-09 18:05:19.354: W/dalvikvm(1366): Unable to resolve superclass of Lcom/example/androidmapsv2/MainActivity; (5)
01-09 18:05:19.354: W/dalvikvm(1366): Link of class 'Lcom/example/androidmapsv2/MainActivity;' failed
01-09 18:05:19.365: D/AndroidRuntime(1366): Shutting down VM
01-09 18:05:19.365: W/dalvikvm(1366): threadid=1: thread exiting with uncaught exception (group=0x40a13300)
01-09 18:05:19.384: E/AndroidRuntime(1366): FATAL EXCEPTION: main
01-09 18:05:19.384: E/AndroidRuntime(1366): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.example.androidmapsv2/com.example.androidmapsv2.MainActivity}: java.lang.ClassNotFoundException: com.example.androidmapsv2.MainActivity
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1983)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.app.ActivityThread.access$600(ActivityThread.java:130)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.os.Handler.dispatchMessage(Handler.java:99)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.os.Looper.loop(Looper.java:137)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.app.ActivityThread.main(ActivityThread.java:4745)
01-09 18:05:19.384: E/AndroidRuntime(1366): at java.lang.reflect.Method.invokeNative(Native Method)
01-09 18:05:19.384: E/AndroidRuntime(1366): at java.lang.reflect.Method.invoke(Method.java:511)
01-09 18:05:19.384: E/AndroidRuntime(1366): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
01-09 18:05:19.384: E/AndroidRuntime(1366): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
01-09 18:05:19.384: E/AndroidRuntime(1366): at dalvik.system.NativeStart.main(Native Method)
01-09 18:05:19.384: E/AndroidRuntime(1366): Caused by: java.lang.ClassNotFoundException: com.example.androidmapsv2.MainActivity
01-09 18:05:19.384: E/AndroidRuntime(1366): at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:61)
01-09 18:05:19.384: E/AndroidRuntime(1366): at java.lang.ClassLoader.loadClass(ClassLoader.java:501)
01-09 18:05:19.384: E/AndroidRuntime(1366): at java.lang.ClassLoader.loadClass(ClassLoader.java:461)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.app.Instrumentation.newActivity(Instrumentation.java:1053)
01-09 18:05:19.384: E/AndroidRuntime(1366): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1974)
01-09 18:05:19.384: E/AndroidRuntime(1366): ... 11 more
UPDATED
i've tried to copy the google-play-services_lib to workspace and red mark disappear
but it come another error. It missing the google-play-services_lib.jar (the lib folder name + .jar). how to fix it
when i click the google-play-services_lib.jar, the remove button doesn't show up(like picture). However i try remove all Android Dependencies and import the others lib again. now it working, but still crash.
I've tried change
MainActivity extends Activity
To
MainActivity extends FragmentActivity
and the layout
<?xml version="1.0" encoding="utf-8"?>
<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="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
</RelativeLayout>
it appear another error. help me, now i'm out of solution for this
Finally, i solved my error. It caused by my eclipse (i guess). When you add the library class, it automatically appear "google-play-services_lib.jar", you don't have to do anything. I reinstall Eclipse and everything work fine
I also faces this kind of the problem,when first time coding for the map with API V2.
Just try using the extends with FragmentActivity instead of the Activity
you have to copy the project(goolge_play_services) into your workspace and then attach it to your project. In above image it show the cross red,so select it and remove and then after once again add attach the library with the project.
It is required to use SupportMapFragment if API version is below 11
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"/>
Important
Don't forget to extend your Activity with FragmentActivity
you have to copy the project(goolge_play_services) into your workspace and then attach it to your project.
What you are doing is importing the project and not checkmarking the copy the project into workspace due to which it showing you wrong mark in added libraries.
So just checkmark the the copy the project into workspace while importing the google_play_services project and then attach it to your project.
As here i can see that you are using the api level 8 and AFAIK the "Fragments" are supported from the 11.
So here you need to use the compatible library of the fragments.
And also make sure that you have also imported the library of the google-play-service in your workspace and added it in your application.
You need to 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.
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
Related
I have seen many other questions like this one on this website and tried changing my code to match but it never solves the problem.
My app loads with some buttons to push. One of them opens a class file that opens a map on the screen. The code for that class is :
public class FuelMap extends Activity
{
private final LatLng locBurb = new LatLng(49.27645, -122.917587);
private final LatLng locSura = new LatLng(49.187500, -122.849000);
private GoogleMap map;
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fuel_map);
//map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map )).getMap();
// Show the Up button in the action bar.
setupActionBar();
}
/**
* Set up the {#link android.app.ActionBar}, if the API is available.
*/
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void setupActionBar()
{
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
{
getActionBar().setDisplayHomeAsUpEnabled(true);
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu)
{
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.fuel_map, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId()) {
case android.R.id.home:
// This ID represents the Home or Up button. In the case of this
// activity, the Up button is shown. Use NavUtils to allow users
// to navigate up one level in the application structure. For
// more details, see the Navigation pattern on Android Design:
//
// http://developer.android.com/design/patterns/navigation.html#up-vs-back
//
NavUtils.navigateUpFromSameTask(this);
return true;
}
return super.onOptionsItemSelected(item);
}
public void OnClickCity(View C)
{
//CameraUpdate update = CameraUpdateFactory.newLatLng(locBurb);
//map.animateCamera(update);
}
public void OnClickBuraby(View B)
{
}
public void OnClickSurray(View S)
{
}
}
But if I uncomment the line: //map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map )).getMap();
and then the app will run until i try to switch it over to the map.
Like I said at the beginning of this I have searched and often found answers on this site relating to my question but none of them gave me any results. I do not believe this problem is due an error of installing the google map stuff needed for the android app since I can load a map. So anyone know what might be the cause?
-LogCat info
04-16 17:16:10.747: D/AndroidRuntime(11672): Shutting down VM
04-16 17:16:10.747: W/dalvikvm(11672): threadid=1: thread exiting with uncaught exception (group=0x41543300)
04-16 17:16:10.752: E/AndroidRuntime(11672): FATAL EXCEPTION: main
04-16 17:16:10.752: E/AndroidRuntime(11672): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.testing.fuelapptesting/com.testing.fuelapptesting.FuelMap}: java.lang.NullPointerException
04-16 17:16:10.752: E/AndroidRuntime(11672): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2059)
04-16 17:16:10.752: E/AndroidRuntime(11672): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084)
04-16 17:16:10.752: E/AndroidRuntime(11672): at android.app.ActivityThread.access$600(ActivityThread.java:130)
04-16 17:16:10.752: E/AndroidRuntime(11672): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195)
04-16 17:16:10.752: E/AndroidRuntime(11672): at android.os.Handler.dispatchMessage(Handler.java:99)
04-16 17:16:10.752: E/AndroidRuntime(11672): at android.os.Looper.loop(Looper.java:137)
04-16 17:16:10.752: E/AndroidRuntime(11672): at android.app.ActivityThread.main(ActivityThread.java:4745)
04-16 17:16:10.752: E/AndroidRuntime(11672): at java.lang.reflect.Method.invokeNative(Native Method)
04-16 17:16:10.752: E/AndroidRuntime(11672): at java.lang.reflect.Method.invoke(Method.java:511)
04-16 17:16:10.752: E/AndroidRuntime(11672): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
04-16 17:16:10.752: E/AndroidRuntime(11672): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
04-16 17:16:10.752: E/AndroidRuntime(11672): at dalvik.system.NativeStart.main(Native Method)
04-16 17:16:10.752: E/AndroidRuntime(11672): Caused by: java.lang.NullPointerException
04-16 17:16:10.752: E/AndroidRuntime(11672): at com.testing.fuelapptesting.FuelMap.onCreate(FuelMap.java:31)
04-16 17:16:10.752: E/AndroidRuntime(11672): at android.app.Activity.performCreate(Activity.java:5008)
04-16 17:16:10.752: E/AndroidRuntime(11672): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079)
04-16 17:16:10.752: E/AndroidRuntime(11672): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023)
04-16 17:16:10.752: E/AndroidRuntime(11672): ... 11 more
04-16 17:16:13.580: I/Process(11672): Sending signal. PID: 11672 SIG: 9
-- activity_Fuel_Map layout
<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"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<fragment
android:id="#+id/maps"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/busCity" />
<TextView
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/maps"
android:layout_alignParentTop="true"
android:layout_marginLeft="33dp"
android:ems="10"
android:text="Map" >
<requestFocus />
</TextView>
<Button
android:id="#+id/buttBuraby"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/map"
android:layout_toRightOf="#+id/buttCity"
android:onClick="OnClickBuraby"
android:text="Buraby" />
<Button
android:id="#+id/buttSurray"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/map"
android:layout_toRightOf="#+id/buttBuraby"
android:onClick="OnClickSurray"
android:text="Surray" />
<Button
android:id="#+id/buttCity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/buttBuraby"
android:layout_alignBottom="#+id/buttBuraby"
android:layout_alignLeft="#+id/maps"
android:onClick="OnClickCity"
android:text="City" />
</RelativeLayout>
-- Manifest file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.testing.fuelapptesting"
android:versionCode="1"
android:versionName="1.0" >
<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"/>
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.testing.fuelapptesting.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="com.testing.fuelapptesting.News"
android:label="#string/title_activity_news"
android:parentActivityName="com.testing.fuelapptesting.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.testing.fuelapptesting.MainActivity" />
</activity>
<activity
android:name="com.testing.fuelapptesting.Messages"
android:label="#string/title_activity_messages" >
</activity>
<activity
android:name="com.testing.fuelapptesting.FuelMap"
android:label="#string/title_activity_fuel_map"
android:parentActivityName="com.testing.fuelapptesting.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.testing.fuelapptesting.MainActivity" />
</activity>
<activity
android:name="com.testing.fuelapptesting.Scanner"
android:label="#string/title_activity_scanner"
android:parentActivityName="com.testing.fuelapptesting.MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.testing.fuelapptesting.MainActivity" />
</activity>
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyC8hlQR9rdDGYMEXQCqpMD2PxzQRrpprPg"/>
</application>
</manifest>
try this link: in google maps V2 ... fragment.getMap() returns null
it appears that the map fragment you are trying to load hasn't been instantiated yet, in the onCreateView().
Hopefully this solves the issue. You might need to post to a handler after the map loads.. essentially a callback.
I t seems that you are using Maps V2 so your declaration in the xml is not right.
It is a fragment not a FragmentLayout as mention in the Android Developer
<?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"/>
Thanks a ton for all the help guys. I final figured out the problem. It was the letter 's'.
In this line: //map = ((MapFragment) getFragmentManager().findFragmentById(R.id.map )).getMap(); I was was pulling the object called map. If you look in my activity_Fuel_Map layout the map object is a TextView.
` <TextView
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/maps"
android:layout_alignParentTop="true"
android:layout_marginLeft="33dp"
android:ems="10"
android:text="Map" >`
So I had to change the (R.id.map) to (R.id.maps) to pull my map fragment.
<fragment
android:id="#+id/maps"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/busCity" />
Thanks again for all the help guys.
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 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.
Current Status: PROBLEM HAS NOT SOLVED YET- NEED HELP..
Im now developing a map app by using the new google maps Android v2..Before I apply it into my real app..I did a testing..and tried to make it works..I followed the documentation by Google Developers
But seems there are some part I missed, But couldn't find them.. Can u identify them for me? I willl give u my source code below...to let u see them clearly..
Here my current MainActivity class(updated): <---I have only this class in my program
package com.madcatworld.demomapv2;
import com.google.android.gms.maps.SupportMapFragment;
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.activity_main);
SupportMapFragment fragment = new SupportMapFragment();
getSupportFragmentManager().beginTransaction()
.add(R.id.map, fragment).commit();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
}
Here is my activity_main.xml: (updated)
<?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.SupportMapFragment" />
Here is my Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.madcatworld.demomapv2"
android:versionCode="1"
android:versionName="1.0" >
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="14" />
<permission
android:name="com.madcatworld.demomapv2.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.madcatworld.demomapv2.permission.MAPS_RECEIVE" />
<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-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<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="xxxxxxxxxxxxxxx" />
<activity
android:name="com.madcatworld.demomapv2.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>
My emulator: a dialog "Get Google Play Services" appear..when I clicked it...a few errors occur as below..
my current error log(updated) it seems shorter than previous error!! :) :
01-25 04:23:18.647: E/AndroidRuntime(503): FATAL EXCEPTION: main
01-25 04:23:18.647: E/AndroidRuntime(503): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://play.google.com/store/apps/details?id=com.google.android.gms flg=0x80000 pkg=com.android.vending }
01-25 04:23:18.647: E/AndroidRuntime(503): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1408)
01-25 04:23:18.647: E/AndroidRuntime(503): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1378)
01-25 04:23:18.647: E/AndroidRuntime(503): at android.app.Activity.startActivityForResult(Activity.java:2817)
01-25 04:23:18.647: E/AndroidRuntime(503): at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:817)
01-25 04:23:18.647: E/AndroidRuntime(503): at android.app.Activity.startActivity(Activity.java:2923)
01-25 04:23:18.647: E/AndroidRuntime(503): at com.google.android.gms.internal.d$2.onClick(Unknown Source)
01-25 04:23:18.647: E/AndroidRuntime(503): at android.view.View.performClick(View.java:2408)
01-25 04:23:18.647: E/AndroidRuntime(503): at android.view.View$PerformClick.run(View.java:8816)
01-25 04:23:18.647: E/AndroidRuntime(503): at android.os.Handler.handleCallback(Handler.java:587)
01-25 04:23:18.647: E/AndroidRuntime(503): at android.os.Handler.dispatchMessage(Handler.java:92)
01-25 04:23:18.647: E/AndroidRuntime(503): at android.os.Looper.loop(Looper.java:123)
01-25 04:23:18.647: E/AndroidRuntime(503): at android.app.ActivityThread.main(ActivityThread.java:4627)
01-25 04:23:18.647: E/AndroidRuntime(503): at java.lang.reflect.Method.invokeNative(Native Method)
01-25 04:23:18.647: E/AndroidRuntime(503): at java.lang.reflect.Method.invoke(Method.java:521)
01-25 04:23:18.647: E/AndroidRuntime(503): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
01-25 04:23:18.647: E/AndroidRuntime(503): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
01-25 04:23:18.647: E/AndroidRuntime(503): at dalvik.system.NativeStart.main(Native Method)
For your information,
I already generate a new api key in my google account by copy my
SHAI num from eclipse..
I did this steps Android Tools> rightclick> Export Signed
Application Packages (to make them link each other, I create new
keystore) My QUESTION IS: should I implement this (no 2)??
Please let me know if u found any mistakes I have made.. thank you
You made a mistake you are trying to access android.R.id.content where in your my activity_main.xml file Mapfragment id is android:id="#+id/map"
So, try this way.
Put this Code in your onCreate(..) method
SupportMapFragment fragment = new SupportMapFragment();
getSupportFragmentManager().beginTransaction()
.add(R.id.map, fragment).commit();
instead of this.
SupportMapFragment fragment = new SupportMapFragment();
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, fragment).commit();
Instead of using the commit() use the .getMap(); method to get and load the map.
GoogleMap mMap;
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
I just put together a new Android project in Eclipse, and so far I only have one package with one activity (the auto-generated code from Eclipse), and all I did was add two buttons to the main.xml layout file.
When I try to debug the app, the emulator crashes and I get the error "Binary XML file line #31: Error inflating class android.widget.FrameLayout."
I'm not even using FrameLayout!
Here is the layout file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#99CCFF">
<Button
android:id="#+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New" />
<Button
android:id="#+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Save" />
</LinearLayout>
And here is the main Activity file (again, this is just the default code that Eclipse generates when you create a new project):
package com.myapp.main;
import android.app.Activity;
import android.os.Bundle;
public class MyApp extends Activity {
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
And just for the heck of it, here's the manifest file as well:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp.main"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name="com.myapp.main.MyApp"
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>
So far as I can see, this is 99% auto-generated code, and I can see no reason why I would be getting an InflateException on "FrameLayout" when I'm not even using a FrameLayout.
So very confused ...
Here is what I get in LogCat:
FATAL EXCEPTION: main
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.myapp.main/com.myapp.main.MyApp}: android.view.InflateException: Binary XML file line #31: Error inflating class android.widget.FrameLayout
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1736)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1752)
at android.app.ActivityThread.access$1500(ActivityThread.java:123)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:993)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:126)
at android.app.ActivityThread.main(ActivityThread.java:3997)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:491)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:841)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:599)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.view.InflateException: Binary XML file line #31: Error inflating class android.widget.FrameLayout
at android.view.LayoutInflater.createView(LayoutInflater.java:596)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
at android.view.LayoutInflater.onCreateView(LayoutInflater.java:644)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:669)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:724)
at android.view.LayoutInflater.inflate(LayoutInflater.java:479)
at android.view.LayoutInflater.inflate(LayoutInflater.java:391)
at android.view.LayoutInflater.inflate(LayoutInflater.java:347)
at com.android.internal.policy.impl.PhoneWindow.generateLayout(PhoneWindow.java:2456)
at com.android.internal.policy.impl.PhoneWindow.installDecor(PhoneWindow.java:2516)
at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:220)
at android.app.Activity.setContentView(Activity.java:1777)
at com.myapp.main.MyApp.onCreate(MyApp.java:20)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1048)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1700)
I'm having trouble seeing what's wrong with your code as well. Could you copy and paste the entire stack trace you get when your app crashes? I think it might give us more of an insight as to what is going on.
You can either get the stack trace from Logcat in Eclipse, or you can open a terminal and type "adb logcat"