Cannot refer to a non-final variable db inside an inner class defined in a different method
<p>I'm developing an app for Android but I got stuck on deleting things from my database!
I'm getting an "Cannot refer to a non-final variable db inside an inner class defined in a different method" error! I know what this error means but I can't seem to find a solution to this.</p>

<p>Here is my code</p>

<pre><code>package iwt.ehb.be.capita_selecta;

//my imports

public class RemoveActivity extends Activity {

    Context context = this;

    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        setContentView(R.layout.remove_activity);

        DBAdapter db = new DBAdapter(this);
        db.open();
        Cursor c = db.getAllTrips();

        if(c.moveToFirst())
        {
            LinearLayout layout = (LinearLayout) findViewById(R.id.layout_removeTrips);

            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
            lp.setMargins(5, 5, 5, 5);

            do {
                Button buttonView = new Button(this);
                buttonView.setBackgroundResource(R.layout.btn_blue);
                buttonView.setLayoutParams(lp);
                buttonView.setText(c.getString(1) + " @ " + c.getString(2));
                final int id_trip = c.getInt(0);
                buttonView.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        System.out.println(id_trip);

                        AlertDialog.Builder alert = new AlertDialog.Builder(context).setTitle("Attention");
                        alert.setMessage("Do you wish to delete this trip?");
                        alert.setIcon(R.drawable.icon);
                        alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                db.deleteSpecificRecord(id_trip);
                            }
                        });
                        alert.setNegativeButton("No",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                            }
                        });

                        alert.show();
                    }
                });
                layout.addView(buttonView);
            } while (c.moveToNext());
        }
        db.close();

        //*******************
        //BACK-button
        //*******************   

        Button back = (Button) findViewById(R.id.back);
        back.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                setResult(RESULT_OK, intent);
                finish();
            }
        });
    }
}
</code></pre>

<p>And I'm getting the error at this line of code <code>db.deleteSpecificRecord(id_trip);</code></p>

<p>If you have any idea on how I can resolve this that would be awsome ;)</p>

<p>Thx 
Kevin</p>
