I need to pass a parameter from an EditText and when I click the button, it’ll start another activity and get that parameter and pass it to a query. It follows:
final Button ara = (Button) findViewById(R.id.maddebutton);
ara.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String maddeno = madde.getText().toString(); //madde is my EditText
Intent intent = new Intent(Anayasa.this, MaddeBul.class);
intent.putExtra("maddeler", maddeno);
startActivity(intent);
}
});
my second class is as follows:
Intent intent = getIntent();
int maddebul = intent.getIntExtra("maddeler", 0); //I don't want to set a default value but it pushes me
try {
Cursor cursor = FetchRecord(db.query("anayasa", SELECT,
"no = maddebul", null, null, null, null));
ShowRecord(cursor);
} finally {
database.close();
}
my FetchRecord(Cursor c) and ShowRecord(Cursor cursor) functions work fine, since I’m using them in other classes. There is “no” column in my “anayasa” database which holds integer values.
On LogCat, it says “no column such maddebul”. It is true, there isn’t. It suppose to be:
SELECT * FROM anayasa WHERE no = maddebul; //as sql command
Any help?
There are multiple problems:
You put
maddebulas String here so need to get it like this:Also you are forming your SQL query wrong,
maddebulis passed as a String to the db, whereas you actually want to pass the value of that variable. So it could be like this instead: