1

I am using this code :

String address = "";
     Geocoder geoCoder = new Geocoder( getBaseContext(), Locale.getDefault());
         try {
           List<Address> addresses = geoCoder.getFromLocation(latitude ,longitude , 1);
           if (addresses.size() > 0) 
              {
              for (int index = 0; 
              index < addresses.get(0).getMaxAddressLineIndex(); index++)
               address += addresses.get(0).getAddressLine(index) + " "; }
                           }
         catch (IOException e) {        
             e.printStackTrace();
           }   
 googleMap_v2.animateCamera(CameraUpdateFactory.zoomTo(15));
          current_location.setText("Latitude:" +  latitude  + ", Longitude:"+ longitude );
          current_address.setText("current Address :" + address ); 
          googleMap_v2.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title("current status")); 
        }}   

This works perfectly on Tablet but gives me this exception on mobile.Stuck with this from last 72 hours unable to figure it out.I really appreciate if somebody can tell what I am supposed to add? THanks in Advance.

Exception:

FATAL EXCEPTION: main
 java.lang.NullPointerException
    at com.maps.maps.MainActivity$1.onMapClick(MainActivity.java:442)
    at com.google.android.gms.maps.GoogleMap$.onMapClick(Unknown Source)
    at com.google.android.gms.maps.internal.h$a.onTransact(Unknown Source)
    at android.os.Binder.transact(Binder.java:297)
    at bor.a(SourceFile:93)
    at maps.af.q.b(Unknown Source)
    at maps.ap.bo.b(Unknown Source)
    at maps.ap.bk.onSingleTapConfirmed(Unknown Source)
    at maps.bt.g.onSingleTapConfirmed(Unknown Source)
    at maps.bt.i.handleMessage(Unknown Source)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:4945)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:511)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
    at dalvik.system.NativeStart.main(Native Method)
jason
  • 3,932
  • 11
  • 52
  • 123
  • 1
    My guess would be that the Geocoder does not work on your phone. A pretty common issue. This would result in you addresses being null perhaps. Is there a java.io.IOException: Service not Available message in your LogCat? – cYrixmorten Oct 20 '13 at 18:36
  • I am using mapOnClickListener() so I am getting lat/lng right then but I dont know why its going to exception ? – jason Oct 20 '13 at 18:43
  • by the way why is addresses null? – jason Oct 20 '13 at 18:43
  • I am simply guessing. Cannot tell exactly where the nullpointer occur from your post. what is on MainActivity.java:442? – cYrixmorten Oct 20 '13 at 18:48
  • But well if I am right, you can see my answer to: http://stackoverflow.com/questions/19059894/google-geocoder-service-is-unavaliable-coordinates-to-address/19061688#19061688 for inspiration for how to get it working despite of geocoder being unavailable. – cYrixmorten Oct 20 '13 at 18:51
  • I ran it again I got java.io.IOException: Service not Available at android.location.Geocoder.getFromLocation(Geocoder.java:136) at com.maps.maps.MainActivity$1.onMapClick(MainActivity.java:437) – jason Oct 20 '13 at 18:52
  • Thanks a ton for the answer and I rebooted the device it worked!! – jason Oct 20 '13 at 18:59

1 Answers1

1

Its Only for getting null value as it is not finding the location. 1)In Your Device check the gps setting and epo setting and if your device is new. 2) Just REBOOT your device..

Subhalaxmi
  • 5,687
  • 3
  • 26
  • 42
  • 1
    Thanks I did the same sometime ago.Do you know how to get listview in popup with arrow indicator? – jason Oct 21 '13 at 08:58
  • are you saying about list view dialog with arrow ?? – Subhalaxmi Oct 21 '13 at 09:37
  • like this http://handytechplus.com/wp-content/uploads/2013/04/facebook-apps-for-mobile-phones.jpg here is my question : http://stackoverflow.com/questions/19415303/listview-toggle-with-animation-like-facebook – jason Oct 21 '13 at 10:00