0

I'm develop app with google maps api v2 from google play service and i'ts work fine .but when i try to run my app on api level 8 device.(xperia arc/old device) it is not loaded and crashed. but on higher api's device it's works fine(like: s4,note3,s5).

I get the information about my location like this:

    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    Criteria criteria = new Criteria();
    String provider = locationManager.getBestProvider(criteria, true);
    Location location = locationManager.getLastKnownLocation(provider);
    double latitude = location.getLatitude();
    double longitude = location.getLongitude();

    //Get location info
    Geocoder gc = new Geocoder(this);
    List<Address> list = gc.getFromLocation(latitude, longitude, 1);
    String country = list.get(0).getCountryName();
    String city = list.get(0).getLocality();
    String street = list.get(0).getAddressLine(0);

    Toast.makeText(MainActivity.this,"country: "+country+"\nCity: "+city+"\nAddress: "+street, 2000).show();

logcat error:

05-19 00:17:11.876: E/AndroidRuntime(2201): FATAL EXCEPTION: main
05-19 00:17:11.876: E/AndroidRuntime(2201): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.bis.work/com.bis.work.MainActivity}: java.lang.NullPointerException
05-19 00:17:11.876: E/AndroidRuntime(2201):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at android.app.ActivityThread.access$1500(ActivityThread.java:121)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at android.os.Handler.dispatchMessage(Handler.java:99)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at android.os.Looper.loop(Looper.java:130)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at android.app.ActivityThread.main(ActivityThread.java:3701)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at java.lang.reflect.Method.invokeNative(Native Method)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at java.lang.reflect.Method.invoke(Method.java:507)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:866)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:624)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at dalvik.system.NativeStart.main(Native Method)
05-19 00:17:11.876: E/AndroidRuntime(2201): Caused by: java.lang.NullPointerException
05-19 00:17:11.876: E/AndroidRuntime(2201):     at com.bibas.workclock.MainActivity.map(MainActivity.java:1890)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at com.bibas.workclock.MainActivity.onCreate(MainActivity.java:150)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-19 00:17:11.876: E/AndroidRuntime(2201):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
05-19 00:17:11.876: E/AndroidRuntime(2201):     ... 11 more

how can i fix it? thank's :)

1 Answers1

1

You need to use Google Play Services for Froyo which is now separate from Google Play Services if you need to support older versions. still Google Play Services for Froyo will work on newer versions too so you do not need 2 separate app builds though.

See: http://developer.android.com/google/play-services/setup.html

Note: Google Play services 4.0.30 (released November 2013) and newer versions require Android 2.3 or higher. If your app supports Android 2.2, you can continue development with the Google Play services SDK, but must instead install Google Play services for Froyo from the SDK Manager.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • I tried to delete the "Google Play Services-lib" and replace it with the"Google Play Services for Froyo" but now i can't import the "import com.google.android.gms.ads.AdRequest; import com.google.android.gms.ads.AdView;" –  May 18 '14 at 22:34
  • you can explain this for me more specific? –  May 18 '14 at 23:40
  • 1
    @user3453502 Unfortunately, Google Play Services for Froyo does not include the Mobile Ads SDK. – matiash May 19 '14 at 00:53
  • @user3453502 They do not support it within one package. Period :) Most likely due to some platform specific code that they want out of main package (basically because Android 2.2 is just 1% of the market and declining – Marcin Orlowski May 19 '14 at 10:24
  • I have lots of my application users with older versions and I have to decipher how one can incorporate support for all versions. sorry about my english (google translate :) ) –  May 19 '14 at 17:23