jesweer wrote: > public class loginactivity extends Activity{ >
Java coding conventions call for type names to be spelled in camel case with an initial upper-case letter. @Override > It's rather a bad idea to indent online code with TAB characters. Use 4 spaces (or 3 or 2) per indent level. > protected void onCreate(Bundle savedInstanceState) { > // TODO Auto-generated method stub > super.onCreate(savedInstanceState); > setContentView(R.layout.activity_main); > Log.e("oncreate", "inside oncreate"); > This is not an error and you should not log it as such. > final EditText userid = (EditText) findViewById(R.id.userid); > final EditText userpassword = (EditText) > findViewById(R.id.userpassword); > Button b1 = (Button) findViewById(R.id.button1); > b1.setOnClickListener(new OnClickListener(){ > > public void onClick(View v) { > Log.e("onclick","inside onclick"); > This is not an error and you should not log it as such. > String username = userid.getText().toString(); > String password = userpassword.getText().toString(); > try{ > Log.e("try","inside try"); > This is not an error and you should not log it as such. > if(username.length() > 0 && password.length() >0) > { > DatabaseAdapter dbUser = new DatabaseAdapter(loginactivity.this); > dbUser.open(); > Log.e("if", "inside if loop"); > This is not an error and you should not log it as such. > if(dbUser.Login(username, password)) > { > Toast.makeText(loginactivity.this,"Successfully Logged In", > Toast.LENGTH_LONG).show(); > }else{ > Toast.makeText(loginactivity.this,"Invalid Username/Password", > Toast.LENGTH_LONG).show(); > } > dbUser.close(); > } > }catch(Exception e) > { > Toast.makeText(loginactivity.this,e.getMessage(), > Toast.LENGTH_LONG).show(); > This is an error and you should log it as such. > } > } > }); > } > } > > > > > package com.example.mylogin; > > import android.content.ContentValues; > import android.content.Context; > import android.database.Cursor; > import android.database.SQLException; > import android.database.sqlite.SQLiteDatabase; > import android.database.sqlite.SQLiteOpenHelper; > import android.util.Log; > > public class DatabaseAdapter{ > public static final String KEY_ROWID = "_id"; > public static final String KEY_USERNAME = "username"; > public static final String KEY_PASSWORD = "password"; > private static final String TAG = "DBAdapter"; > > private static final String DATABASE_NAME = "usersdb"; > private static final String DATABASE_TABLE = "users"; > private static final int DATABASE_VERSION = 1; > > private static final String DATABASE_CREATE = "create table users (_id > integer primary key autoincrement, " > + "username text not null, " + "password text not null);"; > > private Context context = null; > Member variables are already initialized to 'null'. This initialization is redundant. Especially since you don't use the result. 'context' should be 'final'. > private DatabaseHelper DBHelper; > Java coding conventions call for variable and method names to be spelled in camel case with an initial lower-case letter, except for constant variables. This variable should be 'final'. > private SQLiteDatabase db; > > public DatabaseAdapter(Context ctx) { > this.context = ctx; > DBHelper = new DatabaseHelper(context); > } > > public static class DatabaseHelper extends SQLiteOpenHelper { > DatabaseHelper(Context context) { > super(context, DATABASE_NAME, null, DATABASE_VERSION); > } > > public void onCreate(SQLiteDatabase db) { > db.execSQL(DATABASE_CREATE); > } > > public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { > Log.w(TAG, "Upgrading database from version " + oldVersion + " to " > + newVersion + ", which will destroy all old data"); > db.execSQL("DROP TABLE IF EXISTS users"); > onCreate(db); > } > } > > public boolean Login(String username, String password) > Don't forget to use Javadocs in real life. > { > Cursor mCursor = db.rawQuery("SELECT * FROM " + DATABASE_TABLE > + " WHERE username=? AND password=?", new String[] { username, > password }); > if (mCursor != null) { > if (mCursor.getCount() > 0) > { > return true; > } > } > Indentation. > > return false; > } > > public void open() throws SQLException { > db = DBHelper.getWritableDatabase(); > } > > public void close() throws SQLException { > DBHelper.close(); > } > > public long AddUser(String username, String password) { > ContentValues initialValues = new ContentValues(); > initialValues.put(KEY_USERNAME, username); > initialValues.put(KEY_PASSWORD, password); > return db.insert(DATABASE_TABLE, null, initialValues); > > } > } > > i'm [sic] having problem with this program please help me > What is the nature of your problem? -- Lew -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en