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();
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'm making an android map application , using goggle maps v2 , alla went ok until i run the application , it crashs . thes are my files :
MainActivity.java
package com.geo.app;
import android.app.Activity;
import android.app.Fragment;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
public class MainActivity extends FragmentActivity {
static final LatLng HAMBURG = new LatLng(53.558, 9.927);
static final LatLng KIEL = new LatLng(53.551, 9.993);
private GoogleMap map;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
map=((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
Marker hamburg = map.addMarker(new MarkerOptions().position(HAMBURG)
.title("Hamburg"));
Marker kiel = map.addMarker(new MarkerOptions()
.position(KIEL)
.title("Kiel")
.snippet("Kiel is cool")
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.ic_launcher)));
// Move the camera instantly to hamburg with a zoom of 15.
map.moveCamera(CameraUpdateFactory.newLatLngZoom(HAMBURG, 15));
// Zoom in, animating the camera.
map.animateCamera(CameraUpdateFactory.zoomTo(10), 2000, null);
}
}
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<fragment
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>
Manifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.geo.app"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="7"
android:targetSdkVersion="18" />
<permission
android:name="com.geo.app.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<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"/>
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.geo.app.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="AIzaSyB0MLq8L4YCA9GC05iD1V7OYfqlkUa0lhA" />
</application>
</manifest>
The application crashed , and i have this on my LogCat
04-10 10:59:02.545 11918-11918/? D/AndroidRuntime﹕ >>>>>>>>>>>>>> AndroidRuntime START <<<<<<<<<<<<<<
04-10 10:59:02.545 11918-11918/? D/AndroidRuntime﹕ CheckJNI is OFF
04-10 10:59:02.725 11918-11918/? D/AndroidRuntime﹕ --- registering native functions ---
04-10 10:59:03.495 104-205/? I/ActivityManager﹕ Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10000000 cmp=com.geo.app/.MainActivity }
04-10 10:59:03.605 11918-11918/? D/AndroidRuntime﹕ Shutting down VM
04-10 10:59:03.605 11918-11923/? D/dalvikvm﹕ Debugger has detached; object registry had 1 entries
04-10 10:59:03.625 11918-11926/? I/AndroidRuntime﹕ NOTE: attach of thread 'Binder Thread #3' failed
04-10 10:59:03.675 5325-5325/? D/PackageAddedReceiver﹕ package added com.geo.app
04-10 10:59:03.695 104-107/? I/ActivityManager﹕ Start proc com.geo.app for activity com.geo.app/.MainActivity: pid=11928 uid=10082 gids={3003, 1015}
04-10 10:59:04.175 182-182/? D/dalvikvm﹕ GC_EXPLICIT freed 5596 objects / 283440 bytes in 5136ms
04-10 10:59:04.275 3332-11910/? D/RegisterService﹕ insert plugin size 1
04-10 10:59:04.335 104-243/? D/Sensors﹕ open_akm, fd=148
04-10 10:59:04.625 77-77/? D/AK8973﹕ Compass Start
04-10 10:59:04.745 11928-11928/com.geo.app W/dalvikvm﹕ VFY: unable to resolve static field 3704 (MapAttrs) in Lcom/google/android/gms/R$styleable;
04-10 10:59:04.745 11928-11928/com.geo.app D/dalvikvm﹕ VFY: replacing opcode 0x62 at 0x000e
04-10 10:59:04.745 11928-11928/com.geo.app D/dalvikvm﹕ VFY: dead code 0x0010-00ae in Lcom/google/android/gms/maps/GoogleMapOptions;.createFromAttributes (Landroid/content/Context;Landroid/util/AttributeSet;)Lcom/google/android/gms/maps/GoogleMapOptions;
04-10 10:59:04.755 11928-11928/com.geo.app D/AndroidRuntime﹕ Shutting down VM
04-10 10:59:04.755 11928-11928/com.geo.app W/dalvikvm﹕ threadid=1: thread exiting with uncaught exception (group=0x40028a00)
04-10 10:59:04.775 11928-11928/com.geo.app 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:290)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:558)
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 com.geo.app.MainActivity.onCreate(MainActivity.java:26)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1065)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2745)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2797)
at android.app.ActivityThread.access$2300(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2132)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:143)
at android.app.ActivityThread.main(ActivityThread.java:4914)
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)
04-10 10:59:04.845 104-244/? W/ActivityManager﹕ Force finishing activity com.geo.app/.MainActivity
You are missing a meta tag in the manifest file
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
You don't need these
<permission
android:name="com.geo.app.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
Also it is better to check the availability of google play services before intializing GoogleMap object
Edit:
java.lang.NoClassDefFoundError: com.google.android.gms.R$styleable
You haven't referenced google play services library project in your android map project.
In your MainActivity.java class change the fragment import statement
import android.support.v4.app.Fragment
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.
I'm new to Google Maps API and I'm trying to display a map in my application. Every try has failed, I don't understand why.
Here the logcat.
<!-- language: c# --> 04-02 02:03:21.259: W/dalvikvm(24325): VFY: unable to resolve virtual method 3693: Lcom/kurtis/myapp/Mapexample;.getFragmentManager ()Landroid/app/FragmentManager;
04-02 02:03:21.269: W/dalvikvm(24325): VFY: unable to resolve virtual method 3693: Lcom/kurtis/myapp/Mapexample;.getFragmentManager ()Landroid/app/FragmentManager;
04-02 02:03:21.279: W/dalvikvm(24325): VFY: unable to resolve instance field 23
04-02 02:03:21.419: W/dalvikvm(24325): Unable to resolve superclass of Lmaps/p/s; (425)
04-02 02:03:21.429: W/dalvikvm(24325): Link of class 'Lmaps/p/s;' failed
04-02 02:03:21.429: W/dalvikvm(24325): Unable to resolve superclass of Lmaps/y/bo; (3818)
04-02 02:03:21.429: W/dalvikvm(24325): Link of class 'Lmaps/y/bo;' failed
04-02 02:03:21.429: W/dalvikvm(24325): Unable to resolve superclass of Lmaps/i/k; (4206)
04-02 02:03:21.429: W/dalvikvm(24325): Link of class 'Lmaps/i/k;' failed
04-02 02:03:21.429: E/dalvikvm(24325): Could not find class 'maps.i.k', referenced from method maps.z.ag.a
04-02 02:03:21.429: W/dalvikvm(24325): VFY: unable to resolve new-instance 3538 (Lmaps/i/k;) in Lmaps/z/ag;
04-02 02:03:21.979: W/dalvikvm(24325): threadid=1: thread exiting with uncaught exception (group=0x40174560)
04-02 02:03:21.979: E/AndroidRuntime(24325): FATAL EXCEPTION: main
04-02 02:03:21.979: E/AndroidRuntime(24325): java.lang.NoSuchMethodError: com.kurtis.myapp.Mapexample.getFragmentManager
04-02 02:03:21.979: E/AndroidRuntime(24325): at com.kurtis.myapp.Mapexample.onCreate(Mapexample.java:26)
04-02 02:03:21.979: E/AndroidRuntime(24325): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
04-02 02:03:21.979: E/AndroidRuntime(24325): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
04-02 02:03:21.979: E/AndroidRuntime(24325): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
04-02 02:03:21.979: E/AndroidRuntime(24325): at android.app.ActivityThread.access$1500(ActivityThread.java:121)
04-02 02:03:21.979: E/AndroidRuntime(24325): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
04-02 02:03:21.979: E/AndroidRuntime(24325): at android.os.Handler.dispatchMessage(Handler.java:99)
04-02 02:03:21.979: E/AndroidRuntime(24325): at android.os.Looper.loop(Looper.java:130)
04-02 02:03:21.979: E/AndroidRuntime(24325): at android.app.ActivityThread.main(ActivityThread.java:3768)
04-02 02:03:21.979: E/AndroidRuntime(24325): at java.lang.reflect.Method.invokeNative(Native Method)
04-02 02:03:21.979: E/AndroidRuntime(24325): at java.lang.reflect.Method.invoke(Method.java:507)
04-02 02:03:21.979: E/AndroidRuntime(24325): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
04-02 02:03:21.979: E/AndroidRuntime(24325): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
04-02 02:03:21.979: E/AndroidRuntime(24325): at dalvik.system.NativeStart.main(Native Method)
Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="9"
android:targetSdkVersion="16" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera"
android:required="false"/>
<uses-feature android:name="android.hardware.camera.any"
android:required="false" />
<permission android:name="com.kurtis.myapp.permission.MAPS_RECEIVE" android:protectionLevel="signature"/>
<uses-permission android:name="com.kurtis.myapp.permission.MAPS_RECEIVE"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-feature
android:glEsVersion="0x00020000"
android:required="true"/>
<application
android:icon="#drawable/icona"
android:label="#string/app_name" >
<activity
android:name="com.kurtis.myapp.Home"
android:label="#string/app_name"
android:screenOrientation="portrait" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.kurtis.myapp.Mapexample"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:screenOrientation="portrait" >
</activity>
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaXXXXXXXXXXXXXXXXXXXXXXXXXq9M" />
</application>
</manifest>
Activity:
package com.kurtis.myapp;
import com.example.android.R;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import com.google.android.gms.maps.SupportMapFragment;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
#SuppressLint("NewApi")
#TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class Mapexample extends FragmentActivity {
private GoogleMap mMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapexample);
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
// The Map is verified. It is now safe to manipulate the map.
}
}
}
}
...and 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"
class="com.google.android.gms.maps.SupportMapFragment"/>
Have you got any idea to solve this problem?
P.S. sorry for my bad english...
Because You writing your application targeting SDK 9, and you use SupportMapFragment (as you should) in your XML file. Then you have to use getSupportFragmentManager and SupportMapFragment method.
Like that:
map = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
instead of this:
mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap();
It looks like it isn't able to find the maps API. Have you downloaded and configured the Google Play services SDK: https://developers.google.com/maps/documentation/android/start#the_google_maps_api_key
?
Use getSupportFragmentManager() instead of getFragmentManager(). The latter is only defined since Honecomb (and your minsdk is GingerBread) while the former is defined in the support library (that I see you are using since you extend FragmentActivity).
That's why you had to add #TargetApi and #SupressLint... ADT was warning you and you silenced it... =) You should remove those.
In xml file use android:name="com.google.android.gms.maps.SupportMapFragment" instead of
class="com.google.android.gms.maps.SupportMapFragment"
Let me know it`s working