0

カーソルの使用に関して本当に混乱しています。

正常に動作するアクティビティが 1 つあります。コードは次のとおりです。

public class AreaActivity extends ListActivity {

private TextView secondaryTitle;
private Button newArea;
private static final int ACTIVITY_CREATE=0;

private RMDbAdapter rmDbHelper;
private AlertDialog clickOptionsDialog;
private long inspectionId;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_area);
    rmDbHelper = new RMDbAdapter(this);
    rmDbHelper.open();
    Intent i = getIntent();
    inspectionId = i.getLongExtra("Intent_InspectionID", -1);
    setUpViews();
    setLongClick();

    // Get a Cursor for the list items
    Cursor listCursor = rmDbHelper.fetchAllAreasForInspection(inspectionId);
    startManagingCursor(listCursor);           

    // set the custom list adapter     
    setListAdapter(new MyListAdapter(this, listCursor));



}

private void setUpViews() {
    secondaryTitle = (TextView)findViewById(R.id.secondary_title);
    final Cursor cursor = (Cursor) rmDbHelper.fetchInspection(inspectionId);
    String inspectionRef = RMUtilities.notEmpty(cursor.getString(cursor.getColumnIndex( 
            RMDbAdapter.INSPECTION_REF)), "Reference unknown"); 
    String companyName = RMUtilities.notEmpty(cursor.getString(cursor.getColumnIndex( 
            RMDbAdapter.INSPECTION_COMPANY)), "company unknown"); 
    cursor.close();
    final String secondaryTitleText = inspectionRef + ", " + companyName;
    secondaryTitle.setText(secondaryTitleText);
    newArea = (Button)findViewById(R.id.new_area);
    newArea.setOnClickListener(new View.OnClickListener() {                     
        public void onClick(View v) {
            createArea();
        }
    }); 

}

カーソルはデータベースから情報を取得し、それが空でないことを確認し (このサイトで推奨されている別のクラスのコードを使用) TextView、.

ただし、次のアクティビティでこの正確なコードを使用して同じことを行うと、エラーが発生します。

CursorIndexOutOfBoundsException: サイズ 0 のインデックス 0 が要求されました..

コードは同じなので、カーソルを複製するか使用しないかmoveToFirstの問題だと思いますが、何も問題を解決していないようです。

4

1 に答える 1

0

njzk2のおかげで問題が見つかりました-inspectionIdをインテントに渡したときの愚かなエラー。

于 2012-09-17T16:09:28.457 に答える