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?

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?

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!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.