0

このクラスで db cannot be resloved エラーが発生します。displayListView() 関数で。誰でも私がそれを解決するのを手伝ってくれませんか。ありがとう

ここからコードを取得http://kdehairy.com/2012/08/19/using-a-preloaded-sqlite-database-with-sqliteopenhelper/

public class PrepopSqliteDbActivity extends Activity {

// private static final String DB_NAME = "hymnals";

//A good practice is to define database field names as constants



 private SimpleCursorAdapter dataAdapter;
 private Context context;

 @Override
  public void onCreate(Bundle savedInstanceState) {
     super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Our key helper
    ExternalDbOpenHelper repo = ExternalDbOpenHelper.getInstance( context );

    SQLiteDatabase  db = repo.getWritableDatabase();


    displayListView();


}

 private void displayListView() {

 //all hymns are fetched 
  *final Cursor cursor = db.fetchAllHymns();*

  // The desired columns to be bound
  String[] columns = new String[] {

          ExternalDbOpenHelper.HYMN_ID,
          ExternalDbOpenHelper.HYMN_NAME,


  };

  // the XML defined views which the data will be bound to
  int[] to = new int[] {
    R.id.tVid,
    R.id.name,

  };

 // create the adapter using the cursor pointing to the desired data
 //as well as the layout information
     dataAdapter = new SimpleCursorAdapter(
    this, R.layout.activity_main,
    cursor,
    columns,
    to,
    0);

  ListView listView = (ListView) findViewById(R.id.list);
 // Assign adapter to ListView
  listView.setAdapter(dataAdapter);


  listView.setOnItemClickListener(new OnItemClickListener() {

   @Override
   public void onItemClick(AdapterView<?> listView, View view,

     int position, long id) {

// Get the cursor, positioned to the corresponding row in the result set

   Cursor cursor = (Cursor) listView.getItemAtPosition(position);

// Get the state's capital from this row in the database.

   }

  });


 }

  }        
4

1 に答える 1