Problem passing data to new Activity

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Problem passing data to new Activity

Postby defdwight » Fri Jan 02, 2009 9:47 pm

Hello, I have been working on an application and have run into a problem that is baffling me. To preface, I've created a ListView and am trying to perform the simple task of carrying a single piece of data to a new Activity upon the clicking of a selection. Here is most of the code from the Activity that is crashing:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. public class selection extends ListActivity {
  2.         private ListAdapter adapter;
  3.         private Cursor managedCursor;
  4.         /** Called when the activity is first created. */
  5.     @Override
  6.     public void onCreate(Bundle icicle) {
  7.         super.onCreate(icicle);
  8.         setContentView(R.layout.selection);
  9.          
  10.         Cursor managedCursor = getContentResolver().query(People.CONTENT_URI, null, null, null, People.NAME + " ASC");
  11.         startManagingCursor(managedCursor);
  12.        
  13.         String[] columns = new String[]{People.NAME};
  14.        
  15.         int[] to = new int[] { android.R.id.text1 };
  16.         adapter = new SimpleCursorAdapter(
  17.                 this, /* Context. */
  18.                 android.R.layout.simple_list_item_1, /* row layout file */
  19.                 managedCursor, /* Pass in the cursor to bind to. */
  20.                 columns, /* Array of cursor columns to bind to. */
  21.                 to); /* Parallel array of which template objects to bind to those columns. */
  22.  
  23.         /* Bind to new adapter. */
  24.         this.setListAdapter(adapter);
  25.  
  26.     }
  27.    
  28.     @Override
  29.     /* Upon clicking a selection, sends the _ID to the "send" screen for retrieving contact data. */
  30.     protected void onListItemClick(ListView l, View v, int position, long id) {
  31.         super.onListItemClick(l, v, position, id);
  32.         Cursor c = managedCursor;
  33.         c.moveToPosition(position);
  34.         Intent i2 = new Intent(this, sendscreen.class);
  35.         i2.putExtra(sendscreen.iD, id);
  36.         startActivity(i2);
  37.    
  38.      
  39.     }
  40.  
  41. }
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


The crash is happening during the click event, specifically at this line according to the debugger:

Code: Select all
c.moveToPosition(position);


I can't figure out why this is happening. Any help is greatly appreciated!
defdwight
Freshman
Freshman
 
Posts: 6
Joined: Fri Jan 02, 2009 9:29 pm
Location: FL

Top

Postby defdwight » Sat Jan 03, 2009 4:29 am

Nevermind, I went a different route to accomplish this.
defdwight
Freshman
Freshman
 
Posts: 6
Joined: Fri Jan 02, 2009 9:29 pm
Location: FL

Top

Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 8 guests