-3

My code used to work fine, but suddenly it stopped working now its giving me this error:

11-06 00:59:28.852: W/GooglePlayServicesUtil(9518): Google Play services out of date.  Requires 4030500 but found 3266130
11-06 00:59:28.862: W/GooglePlayServicesUtil(9518): Google Play services out of date.  Requires 4030500 but found 3266130
11-06 00:59:28.862: W/GooglePlayServicesUtil(9518): Google Play services out of date.  Requires  4030500 but found 3266130
11-06 00:59:28.862: W/GooglePlayServicesUtil(9518): Google Play services out of date.  Requires 4030500 but found 3266130
11-06 00:59:28.872: W/GooglePlayServicesUtil(9518): Google Play services out of date.  Requires 4030500 but found 3266130
11-06 00:59:28.882: W/GooglePlayServicesUtil(9518): Google Play services out of date.  Requires 4030500 but found 3266130
11-06 00:59:28.882: D/AndroidRuntime(9518): Shutting down VM
11-06 00:59:28.882: W/dalvikvm(9518): threadid=1: thread exiting with uncaught exception (group=0x41933898)
11-06 00:59:28.882: E/AndroidRuntime(9518): FATAL EXCEPTION: main
11-06 00:59:28.882: E/AndroidRuntime(9518): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.carfinder/com.example.carfinder.MainActivity}: java.lang.NullPointerException
 11-06 00:59:28.882: E/AndroidRuntime(9518):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2295)
 11-06 00:59:28.882: E/AndroidRuntime(9518):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2349)
 11-06 00:59:28.882: E/AndroidRuntime(9518):    at android.app.ActivityThread.access$700(ActivityThread.java:159)
 11-06 00:59:28.882: E/AndroidRuntime(9518):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1316)
 11-06 00:59:28.882: E/AndroidRuntime(9518):    at android.os.Handler.dispatchMessage(Handler.java:99)
11-06 00:59:28.882: E/AndroidRuntime(9518):     at android.os.Looper.loop(Looper.java:137)
 11-06 00:59:28.882: E/AndroidRuntime(9518):    at android.app.ActivityThread.main(ActivityThread.java:5419)
 11-06 00:59:28.882: E/AndroidRuntime(9518):    at java.lang.reflect.Method.invokeNative(Native Method)
 11-06 00:59:28.882: E/AndroidRuntime(9518):    at java.lang.reflect.Method.invoke(Method.java:525)
 11-06 00:59:28.882: E/AndroidRuntime(9518):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1187)
 11-06 00:59:28.882: E/AndroidRuntime(9518):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
 11-06 00:59:28.882: E/AndroidRuntime(9518):    at dalvik.system.NativeStart.main(Native Method)
 11-06 00:59:28.882: E/AndroidRuntime(9518): Caused by: java.lang.NullPointerException
 11-06 00:59:28.882: E/AndroidRuntime(9518):    at com.example.carfinder.MainActivity.onCreate(MainActivity.java:38)
 11-06 00:59:28.882: E/AndroidRuntime(9518):    at android.app.Activity.performCreate(Activity.java:5372)
 11-06 00:59:28.882: E/AndroidRuntime(9518):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1104)
 11-06 00:59:28.882: E/AndroidRuntime(9518):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2257)
 11-06 00:59:28.882: E/AndroidRuntime(9518):    ... 11 more

Here is my MainActivity.java

package com.example.carfinder;

import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.view.View;

import com.google.android.gms.location.LocationListener;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

public class MainActivity extends android.support.v4.app.FragmentActivity implements     LocationListener  {

GoogleMap googleMap;

LatLng myPosition ;

// add all necessary things

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);



     // if  Google Play Services are available then

        // Getting reference to the SupportMapFragment of activity_main.xml
        SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

        // Getting GoogleMap object from the fragment
        googleMap = fm.getMap();

        googleMap.getUiSettings().setZoomControlsEnabled(false);

        // Enabling MyLocation Layer of Google Map
        googleMap.setMyLocationEnabled(true);




        // Getting LocationManager object from System Service LOCATION_SERVICE
        LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

        // Creating a criteria object to retrieve provider
        Criteria criteria = new Criteria();

        // Getting the name of the best provider
        String provider = locationManager.getBestProvider(criteria, true);

        // Getting Current Location
        Location location = locationManager.getLastKnownLocation(provider);

        if(location!=null){
        // Getting latitude of the current location
        double latitude = location.getLatitude();

        // Getting longitude of the current location
        double longitude = location.getLongitude();

        // Creating a LatLng object for the current location
        LatLng latLng = new LatLng(latitude, longitude);

         myPosition = new LatLng(latitude, longitude);

         googleMap.moveCamera(CameraUpdateFactory.newLatLng(myPosition));

         // Zoom in the Google Map
         googleMap.animateCamera(CameraUpdateFactory.zoomTo(16));



         }
}

public void onClick_Clear(View v) {
 // Removes all markers, overlays, and polylines from the map.
 googleMap.clear();
}



 public void onClick_Park(View v){
googleMap.addMarker(new MarkerOptions().position(myPosition).title("Parking Position"));

}

 public void onClick_getDirections(View v){


}

 public void onClick_Traffic(View v){


}

@Override
public void onLocationChanged(Location arg0) {
// TODO Auto-generated method stub

}

}

and here is my activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<!--
 Copyright (C) 2012 The Android Open Source Project

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<!-- This can go anywhere in your layout (see other demos for some examples). -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/message_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

<RelativeLayout
  android:layout_width="match_parent"
  android:layout_height="match_parent" >

  <fragment
      android:id="@+id/map"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_alignParentLeft="true"
      class="com.google.android.gms.maps.SupportMapFragment" />

  <Button
      android:id="@+id/btnpark"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_alignParentLeft="true"
      android:onClick="onClick_Park"
      android:text="Park" />

  <Button
      android:id="@+id/btnClear"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentLeft="true"
      android:layout_alignParentTop="true"
      android:onClick="onClick_Clear"
      android:text="Clear" />

  <Button
      android:id="@+id/btnTraffic"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_alignParentRight="true"
      android:onClick="onClick_Traffic"
      android:text="Traffic" />

  <Button
      android:id="@+id/btngetDirections"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_alignParentBottom="true"
      android:layout_centerHorizontal="true"
      android:onClick="onClick_getDirections"
      android:text="Get Directions" />

  </RelativeLayout>

 </LinearLayout>

and finally here is my CarFinder Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.carfinder"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    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"/>
<!-- External storage for caching. -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<!-- My Location -->
<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" >

    <meta-data android:name="com.google.android.maps.v2.API_KEY"
android:value="AIzaSyCnnxM_6pT4ZCvRrvlQjN4gk74ccuTpslg"/>

    <activity
        android:name="com.example.carfinder.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>

The code used to work perfectly but when I updated the the tools in the sdk manager I started getting this code. I tried to delete the project and do it again but still it didn't work and gave me the same error.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • The error message says what to do - 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 `` element: `` –  Nov 05 '13 at 21:37
  • possible duplicate of [After Google Play Service update to version 13 I got an error](http://stackoverflow.com/questions/19723811/after-google-play-service-update-to-version-13-i-got-an-error) – Bryan Herbst Nov 05 '13 at 21:37
  • i added this part but still it didnt work – user2950931 Nov 05 '13 at 21:45
  • "Google Play services out of date. Requires 4030500 but found 3266130" Update yout Google Play Services – laalto Nov 06 '13 at 09:44

1 Answers1

0

As stated in your logcat:

 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" />

There was probably something that happened to your manifest, did you edit it manually? It could be a bug with eclipse.

superuser
  • 731
  • 10
  • 28