title: Cannot be resolved to a type
body: <p>I was wondering if anyone can help me with this. I am trying to add auto-completion to my app with the Google Places API. I am following a tutorial and the following code is what I am having a problem with:</p>
  
  <pre><code>URL googlePlaces = new URL(
                  "https://maps.googleapis.com/maps/api/place/autocomplete/json?input=" +
                  URLEncoder.encode(args[0], "UTF-8") +
                  "&amp;types=geocode&amp;language=en&amp;sensor=true&amp;key=" +
                  getResources().getString(R.string.googleAPIKey));
                  URLConnection tc = googlePlaces.openConnection();
                  BufferedReader in = new BufferedReader(new InputStreamReader(
                          tc.getInputStream()));
  </code></pre>
  
  <p>The line "getResources()" is coming back with a "cannot resolve to a type" error because of the "R.string.googleAPIKey". I will put in my whole code down below:</p>
  
  <pre><code>package com.multinav;
  
  import java.io.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.net.URL;
  import java.net.URLConnection;
  import java.net.URLEncoder;
  import java.util.ArrayList;
  
  import org.json.JSONArray;
  import org.json.JSONException;
  import org.json.JSONObject;
  
  import android.app.Activity;
  import android.location.Criteria;
  import android.location.Location;
  import android.location.LocationManager;
  import android.os.AsyncTask;
  import android.os.Bundle;
  import android.support.v4.app.FragmentActivity;
  import android.text.Editable;
  import android.text.TextWatcher;
  import android.util.Log;
  import android.view.Menu;
  import android.widget.ArrayAdapter;
  import android.widget.AutoCompleteTextView;
  
  import com.google.android.gms.maps.CameraUpdateFactory;
  import com.google.android.gms.maps.GoogleMap;
  import com.google.android.gms.maps.SupportMapFragment;
  import com.google.android.gms.maps.model.LatLng;
  import com.google.android.gms.maps.model.MarkerOptions;
  
  public class MainActivity extends FragmentActivity {
  
      private GoogleMap googleMap;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.item_list);
          setUpMapIfNeeded();
      }
  
      private void setUpMapIfNeeded() {
          // Do a null check to confirm that we have not already instantiated the map.
          if (googleMap == null){
              // Try to obtain the map from the SupportMapFragment.
              googleMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap();
              // Check if we were successful in obtaining the map.
              if (googleMap != null){
                  setUpMap();
              }
          }
  
      }
  
      private void setUpMap() {
          // Enable MyLocation Layer of Google Map
          googleMap.setMyLocationEnabled(true);
  
          // Get LocationManager object from System Service LOCATION_SERVICE
          LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
  
          // Create a criteria object to retrieve provider
          Criteria criteria = new Criteria();
  
          // Get the name of the best provider
          String provider = locationManager.getBestProvider(criteria, true);
  
          // Get Current Location
          Location myLocation = locationManager.getLastKnownLocation(provider);
  
          // Set map type
          googleMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
  
          // Get latitude of the current location
          double latitude = myLocation.getLatitude();
  
          // get longitude of the current location
          double longitude = myLocation.getLongitude();
  
          // Create a LatLng object for the current location
          LatLng latLng = new LatLng(latitude, longitude);
  
          // Show the current location in Google Map
          googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
  
          //Zoom in the Google Map
          googleMap.animateCamera(CameraUpdateFactory.zoomTo(20));
          googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title("BAAMMMM!"));
  
      }
  
      @Override
      public boolean onCreateOptionsMenu(Menu menu) {
          // Inflate the menu; this adds items to the action bar if it is present.
          getMenuInflater().inflate(R.menu.main, menu);
          return true;
      }
  public class Main extends Activity {
          /** Called when the activity is first created. */
      public ArrayAdapter&lt;String&gt; adapter;
      public AutoCompleteTextView textview;
  
      @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.item_list);
              final ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,R.layout.item_list);
              final AutoCompleteTextView textView = (AutoCompleteTextView)
                      findViewById(R.id.autoCompleteTextView1);
              adapter.setNotifyOnChange(true);
              textView.setAdapter(adapter);
               textView.addTextChangedListener(new TextWatcher() {
  
      public void onTextChanged(CharSequence s, int start, int before, int count) {
      if (count%3 == 1) {
      adapter.clear();
                      GetPlaces task = new GetPlaces();
                              //now pass the argument in the textview to the task
                                      task.execute(textView.getText().toString());
          }
      }
  
      public void beforeTextChanged(CharSequence s, int start, int count,
      int after) {
      // TODO Auto-generated method stub
  
      }
  
      public void afterTextChanged(Editable s) {
  
      }
  
      });
  }
  
      class GetPlaces extends AsyncTask&lt;String, Void, ArrayList&lt;String&gt;&gt; {
  
      @Override
                     // three dots is java for an array of strings
      protected ArrayList&lt;String&gt; doInBackground(String... args)
      {
  
      Log.d("gottaGo", "doInBackground");
  
      ArrayList&lt;String&gt; predictionsArr = new ArrayList&lt;String&gt;();
  
  
      try
      {
  
          URL googlePlaces = new URL(
                  "https://maps.googleapis.com/maps/api/place/autocomplete/json?input=" +
                  URLEncoder.encode(args[0], "UTF-8") +
                  "&amp;types=geocode&amp;language=en&amp;sensor=true&amp;key= +
                  getResources().getString(R.string.googleAPIKey));
                  URLConnection tc = googlePlaces.openConnection();
                  BufferedReader in = new BufferedReader(new InputStreamReader(
                          tc.getInputStream()));
  
                  String line;
                  StringBuffer sb = new StringBuffer();
                                  //take Google's legible JSON and turn it into one big string.
                  while ((line = in.readLine()) != null) {
                  sb.append(line);
                  }
                                  //turn that string into a JSON object
                  JSONObject predictions = new JSONObject(sb.toString()); 
                                 //now get the JSON array that's inside that object            
                  JSONArray ja = new JSONArray(predictions.getString("predictions"));
  
                      for (int i = 0; i &lt; ja.length(); i++) {
                          JSONObject jo = (JSONObject) ja.get(i);
                                          //add each entry to our array
                          predictionsArr.add(jo.getString("description"));
                      }
      } 
      catch (IOException e)
      {
  
      Log.e("MultiNAV", "GetPlaces : doInBackground", e);
  
      } 
      catch (JSONException e)
      {
  
      Log.e("MultiNAV", "GetPlaces : doInBackground", e);
  
      }
  
      return predictionsArr;
  
      }
  
      //then our post
  
      @Override
      protected void onPostExecute(ArrayList&lt;String&gt; result){
  
      Log.d("MultiNAV", "onPostExecute : " + result.size());
      //update the adapter
      adapter = new ArrayAdapter&lt;String&gt;(getBaseContext(), R.layout.item_list);
      adapter.setNotifyOnChange(true);
      //attach the adapter to textview
      textview.setAdapter(adapter); 
  
      for (String string : result){
  
      Log.d("MultiNAV", "onPostExecute : result = " + string);
      adapter.add(string);
      adapter.notifyDataSetChanged();
  
      }
  
      Log.d("MultiNAV", "onPostExecute : autoCompleteAdapter" + adapter.getCount());
  
  
          }
  
      }
  
  }
  
  }
  </code></pre>