12 messages in com.googlegroups.android-developersRe: java.lang.IllegalStateException U...
FromSent OnAttachments
kscott04 Dec 2007 21:07 
kscott04 Dec 2007 21:35 
Dan Morrill04 Dec 2007 22:15 
Amit05 Dec 2007 01:46 
kscott05 Dec 2007 10:28 
Mangell07 Dec 2007 14:47 
kscott10 Dec 2007 11:37 
Dr.S28 Dec 2007 13:55 
atri12 Jan 2008 07:43 
geekchique14 Jan 2008 15:45 
Creaven28 Feb 2008 00:18 
SatishG-mail12 Mar 2008 19:42 
Subject:Re: java.lang.IllegalStateException Unable to get field slot
From:Dr.S (drsa@gmail.com)
Date:12/28/2007 01:55:48 PM
List:com.googlegroups.android-developers

Adding rows to an ArrayAdapter is a pain. A better solution is found at: http://code.google.com/android/reference/android/widget/CursorAdapter.html which points out that a CursorAdapter (and thus a SimpleCursorAdapter) must be given a cursor with a column named "_id" or it will fail (specifically, it will produce the error: "java.lang.IllegalStateException Unable to get field slot").

I am an amature programmer who relies on people posting answers to discussion groups, and am thrilled that I *finally* figured something out so that I can make a contribution.

On Dec 10, 12:37 pm, kscott <ksco@gmail.com> wrote:

Well, I ended using a work arround.

I add each row of the cursor into an ArrayAdapter. I then use the the ArrayAdapter to populate the View(.setAdapter() ).

Hope that helps somone.

On Dec 7, 4:48 pm, Mangell <mang@gmail.com> wrote:> I am having a very
similar problem but with AutoCompleteTextView- so I

reduced it down to something along the lines of the list2 sample code by using some built in android.R view Ids, and I get the same exact error.

AutoCompleteTextView textView = (AutoCompleteTextView) findViewById(R.id.item_name); Cursor cur = dbHelper.getItemsListCursor(); SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_1, cur, new String[] {"name"} , new int[] {android.R.id.text1}); textView.setAdapter(adapter);

the cursor has a single column called "name". What are we doing wrong?

On Dec 5, 12:29 pm, kscott <ksco@gmail.com> wrote:

OK I think you need more details. I am just trying to set the Spinner (mRouteTypeSpin) with data from my local SQLite database (in the mCursor object).

//here are the variable definitions private Cursor mCursor;

//here is a snipit form the onCreate method: setContentView(R.layout.transit); Log.d(TAG,"INFLATE XML!!!"); mRouteTypeSpin = (Spinner) findViewById(R.id.routeTypeSpinner); ContentURI curi = ContentURI.create("content://time_table/ route_type"); mCursor = managedQuery(curi, new String[] {"route_type"}, null, null); //this returns a Cursor(mCursor) with one column and three rows in it SpinnerAdapter adapter = new SimpleCursorAdapter(this,android.R.layout.simple_spinner_item_big, mCursor, new String[] {"route_type"}, new int[] {android.R.id.text1});

mRouteTypeSpin.setAdapter(adapter); //this statement causes the IllegalStateException

Here is my XML view (transit.xml): <LinearLayout xmlns:android="http://schemas.android.com/apk/res/ android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <TextView id="@+id/routeTypeLabel" android:layout_width="fill_parent" android:layout_height="20dip" android:text="@string/routeLabel" /> <Spinner id="@+id/routeTypeSpinner" android:layout_width="fill_parent" android:layout_height="wrap_content" android:autoText="true" android:layout_weight="1" > </Spinner> <TextView id="@+id/directionLabel" android:layout_width="fill_parent" android:layout_height="20dip" android:text="@string/directionLabel" /> <Spinner id="@+id/directionSpinner" android:layout_width="fill_parent" android:layout_height="wrap_content" android:autoText="true" android:layout_weight="1" >

</Spinner> <TextView id="@+id/routeLabel" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/routeLabel" /> <Spinner id="@+id/routeSpinner" android:layout_width="fill_parent" android:layout_height="wrap_content" android:autoText="true" android:layout_weight="1" >

</Spinner>

<LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:gravity="center_horizontal" android:orientation="horizontal" >

<Button id="@+id/back" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/back" />

<Button id="@+id/next" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/next" > <requestFocus /> </Button>

<Button id="@+id/settings" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/settings" /> </LinearLayout>

</LinearLayout>

Here the LogCat output: D/ActivityThread( 1057): Performing launch of ActivityRecord{400ca980 {org.kev.transit/org.kev.transit.Transit}} D/Transit ( 1057): INFLATE XML!!! D/Transit ( 1057): trs=android.widget.Spinner@40040268ds=android.widget.Spinner@4004feb8rs=and-roid.widget.Spinner@40050fb0 D/TransitProvider( 1057): urlsandroid.content.ContentURIParser@400ca860 D/TransitProvider( 1057): query=android.content.QueryBuilder@400e1d68 E/CursorWindow( 1057): Bad request for field slot 0,-1. numRows = 3, numColumns = 1 E/Log ( 1057): Saving exception to database. E/AndroidRuntime( 1057): java.lang.IllegalStateException: Unable to get field slot E/AndroidRuntime( 1057): at android.database.CursorWindow.getLong(Native Method) E/AndroidRuntime( 1057): at android.database.AbstractWindowedCursor.getLong(AbstractWindowedCursor.java-: 82) E/AndroidRuntime( 1057): at android.widget.CursorAdapter.getItemId(CursorAdapter.java:110) E/AndroidRuntime( 1057): at android.widget.AdapterView.obtainItemID(AdapterView.java:250) E/AndroidRuntime( 1057): at android.widget.AdapterView.setSelectedPositionInt(AdapterView.java: 510) E/AndroidRuntime( 1057): at android.widget.AbsSpinner.setAdapter(AbsSpinner.java:182) E/AndroidRuntime( 1057): at org.kev.transit.Transit.onCreate(Transit.java:81)

Let me know if I can provide any information. Am I applying the results of my query to the Spinner widget correctly?- Hide quoted text -