title: Getting id by getItemAtPosition method in Android
body: <p>I want to get an id of item, from database, after clicking on item, and then i want to send this id to another activity.</p>
  
  <p>I get an error:</p>
  
  <pre><code>java.lang.ClassCastException: java.lang.String cannot be cast to com.example.myPackage.Place
  </code></pre>
  
  <p>That error is causing by line:</p>
  
  <pre><code>Place mPlace = (Place)(lv.getItemAtPosition(position));
  </code></pre>
  
  <p>Of course, if i change that line on the line below, the application is working but i getting a name of single row showing on the screen instead id.</p>
  
  <pre><code>String str = (String)(lv.getItemAtPosition(position));
  </code></pre>
  
  <p>Here is my full code.</p>
  
  <pre><code>public class VisitedPlaces extends ListActivity {
  
      private ArrayList&lt;String&gt; results = new ArrayList&lt;String&gt;();
  
      protected void onCreate(Bundle savedInstanceState) {
          .
          .
          .
          fillTheList();
          displayResultList();
      }
  
      public void fillTheList(){
          DataBaseHelper dbHelper = new DataBaseHelper(this.getApplicationContext());
  
          List&lt;Place&gt; placesList = new ArrayList&lt;&gt;();
          String sql = "SELECT _id, Name, Description, Latidute, Longtidute FROM Places WHERE Visited=1";
          placesList = dbHelper.getAllPlaces(sql);
  
          for (Place place : placesList){
              results.add(place.getPlaceName());
          }
      }
  
      public void displayResultList() {
  
          ListView lv = getListView();
          lv.addHeaderView(tvNew);
          lv.setTextFilterEnabled(true);
          setListAdapter(new ArrayAdapter&lt;String&gt;(this,android.R.layout.simple_list_item_1, results));
  
          lv.setOnItemClickListener(new OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position,
                      long id) {  
  
  //      String str = (String)(lv.getItemAtPosition(position));
          Place mPlace = (Place)(lv.getItemAtPosition(position)); //HERE IS A PROBLEM
          int mID = mPlace.getID();
  
          Toast.makeText(getApplicationContext(),"Click ListItem: " + mID + ", " + id + ", " , Toast.LENGTH_LONG).show();                              
  
          goToPlaceDescriptions(view, id);
  
              }
          });     
      }
  
      public void goToPlaceDescriptions(View v, long id) {
          Intent intent = new Intent(this, PlaceDescriptions.class);
          intent.putExtra("id", id);
          startActivity(intent);
      }
  }
  </code></pre>
  
  <p>Can somebode help me?</p>