0

I really don't know what is happening to my code. At first, i was able to insert record to my table, then in my second try it just don't run. Please Help. I passed the username through intent which pretty works.

First

 String pass = txtpass.getText().toString();
 String repass = txtpass2.getText().toString();
 String secA = txtans.getText().toString();
 String secQ = txtQ.getSelectedItem().toString();
 Message.message(this, pass+"and"+repass);
 if(pass.equals(repass))
 {
 long id = mh.insertNewAccount(username, pass, secQ, secA);
 if(id < 0)
 Message.message(this, "Unsuccesful");
 else
 {
 Message.message(this, "You may now logged in! Enjoy your experience!");
 Intent intent = new Intent(this, MainScreen.class);
 Bundle bnd=new Bundle();
 bnd.putString("username", username); 
 intent.putExtras(bnd);
 txtpass.setText("");
 txtpass2.setText("");
 txtans.setText("");
 startActivity(intent);
 }
 }
 else
 {
 Message.message_short(this, "Password didn't match!");
 txtpass.setText("");
 txtpass2.setText("");
 }
}

Second - insertNewAccount() Function

 SQLiteDatabase db = helper.getWritableDatabase();
 ContentValues contentValues = new ContentValues();
 contentValues.put(MyHelper.USER_ID, "");
 contentValues.put(MyHelper.USER_USERNAME, name);
 contentValues.put(MyHelper.USER_PASSWORD, pass);
 contentValues.put(MyHelper.USER_SECANS, secA);
 contentValues.put(MyHelper.USER_SECQUE, secQ);
 long id = db.insert(MyHelper.TABLE_USERS, null, contentValues);
 db.close();
 return id;
Saro Taşciyan
5,2365 gold badges33 silver badges50 bronze badges
asked Mar 3, 2014 at 15:41
10
  • 1
    What is the schema of the table (and why do you pass "" for USER_ID)? Commented Mar 3, 2014 at 15:48
  • in SQLiteDatabase db = helper.getWritableDatabase(); what is helper? Try this instead. Commented Mar 3, 2014 at 15:51
  • Would that derive from SQLiteOpenHelper ? Commented Mar 3, 2014 at 16:01
  • Rob's right.. sounds like a schema issue.. like setting USER_ID as a PRIMARY KEY :) Commented Mar 3, 2014 at 21:25
  • USER_ID is actually an autoincrement primary key. I already try to remove it and i just bring it back again. Commented Mar 4, 2014 at 12:38

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.