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.
Related
This question have been asked many more times, and i have tried almost all the solutions given there but nothing worked in my case. This is my xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="com.google.android.gms.maps.SupportMapFragment"
/>
this is my java code
public class Storesearch extends FragmentActivity{
private GoogleMap map;
private LocationManager locationManager;
private Location mylocation;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_storesearch);
determineLocation();
}
protected void onStart() {
super.onStart();
setupMap();
appMapSettings();
spotCurrentLocation(mylocation);
}
public void setupMap(){
if(map==null){
SupportMapFragment mf=(SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.map);
map=mf.getMap();
}
}
This is my manifest
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.fyp.searchstore"
android:versionCode="1"
android:versionName="1.0" >
<permission
android:name="com.fyp.searchstore.permission.MAPS_RECEIVE"
android:protectionLevel="signature" />
<uses-permission android:name="com.fyp.searchstore.permission.MAPS_RECEIVE" />
<meta-data
android:name="com.google.android.maps.v2.API_KEY"
android:value="API KEY"/>
<meta-data
android:name="com.google.android.gms.version"
android:value="19" />
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-feature
android:glEsVersion="0x00020000"
android:required="true" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Storesearch"
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>
and finally my logcat report
10-17 04:45:12.664: D/AndroidRuntime(2461): Shutting down VM
10-17 04:45:12.664: W/dalvikvm(2461): threadid=1: thread exiting with uncaught exception (group=0xb2ad1ba8)
10-17 04:45:12.684: E/AndroidRuntime(2461): FATAL EXCEPTION: main
10-17 04:45:12.684: E/AndroidRuntime(2461): Process: com.fyp.searchstore, PID: 2461
10-17 04:45:12.684: E/AndroidRuntime(2461): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.fyp.searchstore/com.fyp.searchstore.Storesearch}: android.view.InflateException: Binary XML file line #2: Error inflating class fragment
10-17 04:45:12.684: E/AndroidRuntime(2461): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
10-17 04:45:12.684: E/AndroidRuntime(2461): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
10-17 04:45:12.684: E/AndroidRuntime(2461): at android.app.ActivityThread.access$800(ActivityThread.java:135)
10-17 04:45:12.684: E/AndroidRuntime(2461): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
10-17 04:45:12.684: E/AndroidRuntime(2461): at android.os.Handler.dispatchMessage(Handler.java:102)
10-17 04:45:12.684: E/AndroidRuntime(2461): at android.os.Looper.loop(Looper.java:136)
10-17 04:45:12.684: E/AndroidRuntime(2461): at android.app.ActivityThread.main(ActivityThread.java:5017)
10-17 04:45:12.684: E/AndroidRuntime(2461): at java.lang.reflect.Method.invokeNative(Native Method)
10-17 04:45:12.684: E/AndroidRuntime(2461): at java.lang.reflect.Method.invoke(Method.java:515)
10-17 04:45:12.684: E/AndroidRuntime(2461): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
its giving me error on second line of xml file. i m using revision20 of google play services while my android API is version 19. Does the problem i m having is due to these versions? Thanks in advance
Look like this guy had the same problem than you: Stackoverflow
Look to the second answer. Did you copy the .jar file or did you add it as a referenced library ?
And had you download the Android Support Library ?
hello are you trying to check it on android emulator? if yes than please use google-api emulator which will have support library in it. try to check in real android device and if its still giving you same error than add google play services in your project also.
Im almost just a beginner in android. I was trying to make a very simple app with google maps, ie just displaying maps. I followed the following link:
file:///C:/Android/Android%20Google%20Maps%20V2%20Tutorial.htm
But when I test it on my device it says it has stopped working and closes.
Here is my Manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.googleapi"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="11"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!-- Required to show current location -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.googleapi.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="AIzaSyA5BsIL-3rppsOxQOuX4gBZT3c0cTHNbWc" />
</application>
</manifest>
Acyivity code is: (I tried extending FragementActivity but dosent work with it too.)
package com.example.googleapi;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapFragment;
import android.os.Bundle;
import android.app.Activity;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.widget.Toast;
public class MainActivity extends FragmentActivity {
// Google Map
private GoogleMap googleMap;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
// Loading map
initilizeMap();
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* function to load map. If map is not created it will create it for you
* */
private void initilizeMap() {
if (googleMap == null) {
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
// check if map is created successfully or not
if (googleMap == null) {
Toast.makeText(getApplicationContext(),
"Sorry! unable to create maps", Toast.LENGTH_SHORT)
.show();
}
}
}
#Override
protected void onResume() {
super.onResume();
initilizeMap();
}
}
and XML code is( some part of it):
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
My logcat is:
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2245)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5017)
at java.lang.reflect.Method.invokeNative(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
Caused by: android.view.InflateException: Binary XML file line #6: Error inflating class fragment
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:713)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:755)
at android.app.Activity.setContentView(Activity.java:1929)
at com.example.googleapi.MainActivity.onCreate(MainActivity.java:20)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
Caused by: java.lang.IllegalStateException: The meta-data tag in your app's AndroidManifest.xml
does not have the right value. Expected 4030500 but found 0.
You must have the following declaration within the <application> element:
<meta-data android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
at com.google.android.gms.common.GooglePlayServicesUtil.n(Unknown Source)
at com.google.android.gms.common.GooglePlayServicesUtil.isGooglePlayServicesAvailable(Unknown Source)
at com.google.android.gms.maps.internal.q.v(Unknown Source)
at com.google.android.gms.maps.internal.q.u(Unknown Source)
at com.google.android.gms.maps.MapsInitializer.initialize(Unknown Source)
at com.google.android.gms.maps.MapFragment$b.cE(Unknown Source)
at com.google.android.gms.maps.MapFragment$b.a(Unknown Source)
at com.google.android.gms.dynamic.a.a(Unknown Source)
at com.google.android.gms.dynamic.a.onInflate(Unknown Source)
at com.google.android.gms.maps.MapFragment.onInflate(Unknown Source)
at android.app.Activity.onCreateView(Activity.java:4785)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:689)
... 21 more
I have googled a lot about it and got some direct questions on it but no answer ?? .
It seems many have the same problem.Can anyone help with this problem. I want to develop an app but not able to proceed as Google mpas api is main part of it.
Your are missing a meta tag in the application tag of manifest
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
You should use SupportMapFragment instead of MapFragment.
Change
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
to
<fragment
android:id="#+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
Change
googleMap = ((MapFragment) getFragmentManager().findFragmentById(
R.id.map)).getMap();
TO
googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(
R.id.map)).getMap();
Whatever you have done is ok with older version of GooglePlayServices, but its apparently visible from your logcat that you are using GooglePlayServices 13 or higher so you need to add the meta data tag in your manifest just the way Raghunandan have answered.
I need to use actionbarsherlock in my test project. Here is my activity:
public class MainActivity extends SherlockActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
#Override
public boolean onCreateOptionsMenu(com.actionbarsherlock.view.Menu menu) {
// TODO Auto-generated method stub
return super.onCreateOptionsMenu(menu);
}
}
and this is my manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.actionbarsherlocktest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.actionbarsherlocktest.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>
but when I run as an android application, it is said:
FATAL EXCEPTION: main
java.lang.NoClassDefFoundError: com.actionbarsherlock.R$styleable
at com.actionbarsherlock.internal.ActionBarSherlockCompat.generateLayout(ActionBarSherlockCompat.java:998)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.installDecor(ActionBarSherlockCompat.java:915)
at com.actionbarsherlock.internal.ActionBarSherlockCompat.setContentView(ActionBarSherlockCompat.java:849)
at com.actionbarsherlock.app.SherlockActivity.setContentView(SherlockActivity.java:229)
at com.example.actionbarsherlocktest.MainActivity.onCreate(MainActivity.java:12)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
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:123)
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:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
can someone help me?
This seems to be a problem in how you have your project and its libraries configured. The compiler is unable to find the auto generated R class for ABS which probably means it's just not being generated. You should try reimporting ABS into your project. This video on how to get started with the library might help: http://www.youtube.com/watch?v=4GJ6yY1lNNY.
Have you imported the libraries properly?
Well try this ! this might help you:
Libraries do not get added to APK anymore after upgrade to ADT 22
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 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" />