i've a class in this app that should create and use a database, but Eclipse tell me that the sqlite methods are undefined.
Seem to be a context problem but i don't understand how to fix, have i to extend a different class instead of Activity?
package com.android.userdata;
import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class getdata extends Activity {
private final String MY_DATABASE_NAME = "DataStore";
private final String MY_DATABASE_TABLE = "UserData";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.userdata);
SQLiteDatabase myDB = null;
/* Create the Database (no Errors if it already exists) */
this.createDatabase(MY_DATABASE_NAME, 1, MODE_PRIVATE, null);
myDB = this.openDatabase(MY_DATABASE_NAME, null);
myDB.execSQL("CREATE TABLE IF NOT EXISTS "
+ MY_DATABASE_TABLE
+ " (LastName VARCHAR, FirstName VARCHAR,"
+ " Country VARCHAR, Age INT(3));");
Button btn = (Button) findViewById(R.id.confirm);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getdata.this, "Hai Premuto il Pulsante", Toast.LENGTH_SHORT).show();
}
});
}
}
Thanks for your help!