The code is for the registation table for finace app
The user registers into the app and it is stored into the database
later it will used to login into app
my problem is here that the database is being created but the table is not getting created and the appication is closing if we click on the submit button
similarly with the reset button
actually i should enter the data into the table but
public class Register extends Activity {
String str1;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.register);
button for going back to the login page
Button bk=(Button)findViewById(R.id.back);
bk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent1=new Intent(v.getContext(), PersonelFinaceAppActivity.class);
startActivityForResult(intent1, 0);
}
});
button for the reset button it resets all the fields
Button rst=(Button)findViewById(R.id.reset);
rst.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
EditText et=(EditText)findViewById(R.id.fn);
et.setText("");
et=(EditText)findViewById(R.id.ln);
et.setText("");
et=(EditText)findViewById(R.id.un);
et.setText("");
et=(EditText)findViewById(R.id.pass);
et.setText("");
et=(EditText)findViewById(R.id.monincome);
et.setText("");
TextView tv =(TextView)findViewById(R.id.textView1);
tv.setText("Firstname ");
tv =(TextView)findViewById(R.id.textView2);
tv.setText("Lastname");
tv =(TextView)findViewById(R.id.textView3);
tv.setText("Username");
tv =(TextView)findViewById(R.id.textView6);
tv.setText("Password");
tv =(TextView)findViewById(R.id.textView7);
tv.setText("Monthlyincome");
}
});
check button for checking the useralready exits in the database of not
Button chk=(Button)findViewById(R.id.chk);
chk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
String User;
EditText Username = (EditText)findViewById(R.id.un);
User = Username.getEditableText().toString().trim();
SQLiteDatabase db1;
db1 = openOrCreateDatabase("Userdetails.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
db1.setVersion(3);
db1.setLocale(Locale.getDefault());
db1.setLockingEnabled(true);
try{Cursor c1=db1.rawQuery("select Username from details1 where Username='"+User+"'",null);
if(c1.moveToNext()){showDialog(1);}
else{showDialog(2);}
}
catch (Exception e) {
// TODO: handle exception
}
}
});
the problem arises here the submit button
it has to perform all the action of the app
Button sub=(Button)findViewById(R.id.submit);
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
String First;
String Last;
String User;
String Pass;
String monthincome;
@SuppressWarnings("unused")
long l;
EditText Firstname =(EditText)findViewById(R.id.fn);
EditText Lastname = (EditText)findViewById(R.id.ln);
EditText Username = (EditText)findViewById(R.id.un);
EditText Password = (EditText)findViewById(R.id.pass);
EditText moninc = (EditText)findViewById(R.id.monincome);
First = Firstname.getEditableText().toString().trim();
Last = Lastname.getEditableText().toString().trim();
Pass = Password.getEditableText().toString().trim();
User = Username.getEditableText().toString().trim();
monthincome = moninc.getEditableText().toString().trim();
if(Firstname.length()<1 || Lastname.length()<1 || Password.length()<1 || Username.length()<1 || moninc.length()<1)
{showDialog(3);}
else{SQLiteDatabase db1;
db1 = openOrCreateDatabase("Userdetails.db", SQLiteDatabase.CREATE_IF_NECESSARY, null);
db1.setVersion(3);
db1.setLocale(Locale.getDefault());
db1.setLockingEnabled(true);
final String CREATE_TABLE_DETAILS ="CREATE TABLE details1 (" + "Username INTEGER PRIMARY KEY ," + "Firstname TEXT," + "Lastname TEXT," + "Password TEXT," + "Monthlyincome TEXT);";
db1.execSQL(CREATE_TABLE_DETAILS);
try{Cursor c1=db1.rawQuery("select Username from details1 where Username='"+User+"'",null);
if(c1.moveToNext())
{showDialog(4);}
else{
ContentValues values1 = new ContentValues();
values1.put("Firstname", First);
values1.put("Lastname", Last);
values1.put("Username", User);
values1.put("Password", Pass);
values1.put("Monthlyincome", monthincome);
db1.insert("details1", null, values1);
showDialog(5);
}
}
catch(Exception e)
{}
finally
{}
}
}
});
}
}
need help in only the submit button plz help
figured it out the table creation is changed and its done
SQLiteDatabase db1;
db1 = openOrCreateDatabase(“Userdetails.db”, SQLiteDatabase.CREATE_IF_NECESSARY, null);
db1.setVersion(3);
db1.setLocale(Locale.getDefault());
db1.setLockingEnabled(true);
final String CREATE_TABLE = “CREATE TABLE IF NOT EXISTS details1 (“+ “ID INTEGER primary key AUTOINCREMENT,”+ “Firstname TEXT,”+ “Lastname TEXT,”+ “Username TEXT,”+ “Password TEXT,” + “Monthlyincome TEXT);”;
db1.execSQL(CREATE_TABLE);