The problem with your code is that you are trying to define a function (buildGoogleApiClient) inside another function (onCreate) that is not possible with Java.
protected void onCreate(Bundle savedInstanceState) {
Thus, mainly in Java, curly braces mark the boundaries of a block of code. A code block can be an if-block, while-block or function-block, etc. Java does not allow a function block inside a function block. Only a block class can contain a function block.
So, you need to define your functions directly in the block class.
public class Blah extends Activity implements BlahInterface { private BlahApiClient mBlahApiClient; protected synchronized void buildBlahApiClient() { mBlahApiClient = new BlahApiClient.Builder(this) .addConnectionCallbacks(this) .addOnConnectionFailedListener(this) .addApi(LocationServices.API) .build(); } protected void onCreate( Bundel savedInstanceState ) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
source share