2011-01-26 64 views
1
int columnIndexFromAddrCountry; 

public FavoritesActAdapter(Context context, int layout, 
     Cursor c, String[] from, int[] to) { 
    super(context, layout, c, from, to); 
    gnCursor = c; 

    columnIndexFromAddrCountry = 
     c.getColumnIndex(DBAdapter.KEY_FROM_ADDR_COUNTRY); 

} 

@Override 
public void bindView(View view, Context context, Cursor cursor) { 
    gnCursor = getCursor(); 

    final String fromAddrCountry = 
     gnCursor.getString(columnIndexFromAddrCountry); 

     ... 

     super.bindView(view, context, cursor); 
} 

爲什麼我會收到IllegalStateExceptionIllegalStateException:從第0行獲取字段插槽col -1失敗

IllegalStateException異常:從0行山坳-1得到磁場槽 失敗

是什麼異常是什麼意思?唯一的例外是拋出此行

final String fromAddrCountry = gnCursor.getString(columnIndexFromAddrCountry); 

因爲columnIndexFromAddrCountry-1。 該列存在,其他十列可以解析。什麼會導致這個問題?

在此先感謝!

回答

2

DBAdapter.KEY_FROM_ADDR_COUNTRY是什麼設置?

Cursor doc

公共抽象INT getColumnIndex (字符串COLUMNNAME)

自:API等級1返回給定列 名 從零開始的索引,或者-1,如果列不存在 。如果你希望在列 存在使用 getColumnIndexOrThrow(String)來代替, 這將使錯誤更加清晰

所以,你可以使用getColumnIndexOrThrow(String)有一個更好的錯誤信息,這將有助於你的調試。

+0

`DBAdapter.KEY_FROM_ADDR_COUNTRY`是一個公共靜態String,它表示列的名稱。相同的字符串用於創建表。 – 2011-01-26 22:19:34

相關問題