Null pointer exception in LocationManager

Put your problem here if it does not fit any of the other categories.

Null pointer exception in LocationManager

Postby nithin.warier » Fri Mar 07, 2008 8:11 am

i tried to get my location using this code.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.       public void onCreate(Bundle icicle) {
  2.  
  3.         super.onCreate(icicle);
  4.  
  5.         myLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
  6.  
  7.         location =  myLocationManager.getCurrentLocation("gps");
  8.  
  9.         listObj = new ArrayList();
  10.  
  11.         tv = new TextView(this);
  12.  
  13.         tv.setText(location.toString());
  14.  
  15.     }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


but i am getting the null pointer exception, please tell any error in this...

Thanks
Nithin
nithin.warier
Experienced Developer
Experienced Developer
 
Posts: 87
Joined: Thu Feb 28, 2008 12:05 pm
Location: Malappuram Kerala India

Top

Postby nithin.warier » Fri Mar 07, 2008 10:58 am

I tried in this way also, using Map, still its not working... again showing Null pointer exception..

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.       myLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
  2.  
  3.         loc =  myLocationManager.getCurrentLocation("gps");
  4.  
  5.         lat = loc.getLatitude()*1E6;
  6.  
  7.         lng = loc.getLongitude()*1E6;
  8.  
  9.         Point point1 = new Point(lat.intValue(), lng.intValue());
  10.  
  11.         mc.centerMapTo(point1, false);
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


please help buddies...

Thanks
Nithin
nithin.warier
Experienced Developer
Experienced Developer
 
Posts: 87
Joined: Thu Feb 28, 2008 12:05 pm
Location: Malappuram Kerala India

Postby plusminus » Fri Mar 07, 2008 1:01 pm

Hello nithin.warier,

the first thing to check is where the NullPointerException happens.

Maybe you forgot to add the permissions to the AndroidManifest.xml:
Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1.     <uses-permission android:name="android.permission.ACCESS_LOCATION"/>
  2.     <uses-permission android:name="android.permission.ACCESS_GPS"/>
Parsed in 0.001 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby nithin.warier » Fri Mar 07, 2008 1:32 pm

Hi plusminus,

Thanks a lot.. Now, its working. This problem eat a lot of my time, thanks a lot.. Now its working. NO null pointer exception.

But showing my location as San Francisco. Actually i am in India.

The code is this,
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  myLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
  2.  
  3.         loc =  myLocationManager.getCurrentLocation("gps");
  4.  
  5.         lat = loc.getLatitude()*1E6;
  6.  
  7.         lng = loc.getLongitude()*1E6;
  8.  
  9.         point1 = new Point(lat.intValue(), lng.intValue());
  10.  
  11.         mc.centerMapTo(point1, false);
  12.  
  13. mc.zoomTo(6);
  14.  
  15.         setContentView(myMap);
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


what may be the problem..
nithin.warier
Experienced Developer
Experienced Developer
 
Posts: 87
Joined: Thu Feb 28, 2008 12:05 pm
Location: Malappuram Kerala India

Postby plusminus » Fri Mar 07, 2008 4:38 pm

Hello nithin,

a.) how should it know where you are ?
b.) Read here :arrow: viewtopic.php?t=105

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby nithin.warier » Sat Mar 08, 2008 5:36 am

Hi plusminus

thanks
nithin.warier
Experienced Developer
Experienced Developer
 
Posts: 87
Joined: Thu Feb 28, 2008 12:05 pm
Location: Malappuram Kerala India

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 19 guests