tags:

views:

24

answers:

0

There are two screens in my app. in first screen I take username and password, open DB connection and insert them, on click button in screen 1 I am bring up second screen and do the authentication by comparing stored password with current password that user inputs in screen 2. Application in emulator crashes when I click on submit button in screen 1. the AndroiManifest and xml widgets are all fine, please let me know the possible error from your experience. do I close db (db.close) once I call second screen or keep it open. Thanks

---Screen 1--- public class Test extends Activity { public Context mContext; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { final DBAdapter db = new DBAdapter(this); db.open(); super.onCreate(savedInstanceState); setContentView(R.layout.main); mContext=this; //OnClickListener; Button sign_in_button = (Button) findViewById(R.id.sign_in_button);//using button from first screen to load setup page

    sign_in_button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            long id;
            id = db.insertTitle(
                    "password",
                    "C# 2008 Programmer's Reference",
                    "Wrox");        
            id = db.insertTitle(
                    "047017661X",
                    "Professional Windows Vista Gadgets Programming",
                    "Wrox");
            // TODO Auto-generated method stub
            Intent i = new Intent(mContext, Secondscreen.class);//loads up the set up figure "Enter Name Screen"
             db.close();
            startActivity(i);
        }
    });
}

}


Screen 2

public class Secondscreen extends Activity{ TextView text_result; final DBAdapter db = new DBAdapter(this);

public Context mContext;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
     setContentView(R.layout.secondscreen);//
     db.open(); 
    Cursor c = db.getTitle(2);
    text_result.setText( c.getString(0));
    db.close();

} }