0

I am brand new to Android development. Hopefully this is an easy one. Relevant code (I hope) below.

import android.location.LocationManager;
import android.content.Context;

LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

I get the following: Error: error: cannot find symbol method getSystemService(String)

All the code samples I am seeing say to do the above. I do notice that if I do this instead...

Context cont;
locationManager = (LocationManager) cont.getSystemService(Context.LOCATION_SERVICE);

then that particular error goes away, but of course, you have an uninstatiated variable cont. As mentioned, I am new to Android, so I don't know what a Context object is and how to get one. I've been doing a little research on that. However, all the code samples I've seen seem to be of the variety where the method getSystemService is called without any Context object, so presumably it's compiling fine for everyone but me. Any ideas?

On a different note, the preview is coming up rather odd in the code tags. "getSystemService" is in red and crossed out, "corrected" with "get SystemService" with a space between "get" and "System". Is this a function of the code tags? This is Java code and the function is "getSystemService" with no space. Is there some auto-correct HTML parsing going on?

2
Contributors
2
Replies
22
Views
2 Years
Discussion Span
Last Post by open_1
0

OK, as far as the parsing goes, it showed up in the preview, but not the actual post. I guess that was just a suggestion to me and an opportunity to change it before the official post if it was indeed wrong.

The coding question remains. How do I get the compiler to find the getSystemService method?

0

have you solve the problem? i meet the same thing now,could you give me some help,my email is guoyang20130608@163.com,thankyou very much!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.