Hi everybody!
Can someone help me to see more clearly when I click on the Login button, the android studio emulator shows me this: App has stopped, open again,
here are my codes:
Databasehelper:
- public class DatabaseHelper extends SQLiteOpenHelper {
- private static final int DATABASE_VERSION=1;
- private static final String DATABASE_NAME="Donsang.db";
- private static final String TABLE_NAME="Inscription";
- private static final String COLUMN_ID="id";
- private static final String COLUMN_PSEUDO="pseudo";
- private static final String COLUMN_NAME="nom";
- private static final String COLUMN_PHONE="phone";
- private static final String COLUMN_NAISSANCE="naissance";
- //private static final String COLUMN_VILLE="ville";
- private static final String COLUMN_DATEDON="datedon";
- // private static final String COLUMN_SEXE="sexe";
- private static final String COLUMN_IMAGE="image";
- // private static final String COLUMN_GROUPE="groupe";
- SQLiteDatabase db;
- private static final String TABLE_CREATE="create table Inscription (id integer primary key not null auto_increment,"+
- "pseudo text not null,nom text not null,phone text not null,naissance text not null" +
- "datedon text not null,image Blob";
- public DatabaseHelper(Context context)
- {
- super(context,DATABASE_NAME,null,DATABASE_VERSION);
- }
- @Override
- public void onCreate(SQLiteDatabase db) {
- db.execSQL(TABLE_CREATE);
- this.db=db;
- }
- @Override
- public void onUpgrade(SQLiteDatabase db, int i, int i1) {
- String query="DROP TABLE IF EXISTS " + TABLE_NAME;
- db.execSQL(query);
- this.onCreate(db);
- }
- public boolean insertData(String pseudo,String nom,String phone,String naissance,String datedon,
- String image)
- {
- SQLiteDatabase db=this.getWritableDatabase();
- ContentValues contentValues=new ContentValues();
- contentValues.put(COLUMN_PSEUDO,pseudo);
- contentValues.put(COLUMN_NAME,nom);
- contentValues.put(COLUMN_PHONE,phone);
- contentValues.put(COLUMN_NAISSANCE,naissance);
- // contentValues.put(COLUMN_VILLE,ville);
- contentValues.put(COLUMN_DATEDON,datedon);
- // contentValues.put(COLUMN_SEXE,sexe);
- contentValues.put(COLUMN_IMAGE,image);
- // contentValues.put(COLUMN_GROUPE,groupe);
- long result= db.insert(TABLE_NAME,null,contentValues);
- if(result==-1)
- return false;
- else
- return true;
- }
- public List
getAll() - {
- String[] columns = {
- COLUMN_PSEUDO,
- COLUMN_NAME,
- COLUMN_PHONE,
- COLUMN_NAISSANCE,
- COLUMN_DATEDON,
- COLUMN_IMAGE
- };
- String sortOrder =
- COLUMN_PSEUDO + " ASC";
- List
inscritList = new ArrayList (); - SQLiteDatabase db = this.getReadableDatabase();
- Cursor cursor = db.query(TABLE_NAME, //Table to query
- columns, //columns to return
- null, //columns for the WHERE clause
- null, //The values for the WHERE clause
- null, //group the rows
- null, //filter by row groups
- sortOrder);
- if (cursor.moveToFirst()) {
- do {
- Inscription user = new Inscription();
- user.setId(Integer.parseInt(cursor.getString(cursor.getColumnIndex(COLUMN_ID))));
- user.setPseudo(cursor.getString(cursor.getColumnIndex(COLUMN_PSEUDO)));
- user.setNom(cursor.getString(cursor.getColumnIndex(COLUMN_NAME)));
- user.setPhone(cursor.getInt(cursor.getColumnIndex(COLUMN_PHONE)));
- user.setNaissance(cursor.getString(cursor.getColumnIndex(COLUMN_NAISSANCE)));
- user.setDate(cursor.getString(cursor.getColumnIndex(COLUMN_DATEDON)));
- user.setImage(cursor.getBlob(cursor.getColumnIndex(COLUMN_IMAGE)));
- // Adding user record to list
- inscritList.add(user);
- } while (cursor.moveToNext());
- }
- cursor.close();
- db.close();
- // return user list
- return inscritList;
- }
- public void updateInscription(Inscription inscris) {
- SQLiteDatabase db = this.getWritableDatabase();
- ContentValues values = new ContentValues();
- values.put(COLUMN_PSEUDO, inscris.getPseudo());
- values.put(COLUMN_NAME, inscris.getNom());
- values.put(COLUMN_PHONE, inscris.getPhone());
- values.put(COLUMN_NAISSANCE, inscris.getNaissance());
- values.put(COLUMN_DATEDON, inscris.getDate());
- values.put(COLUMN_IMAGE, inscris.getImage());
- // updating row
- db.update(TABLE_NAME, values, COLUMN_ID + " = ?",
- new String[]{String.valueOf(inscris.getId())});
- db.close();
- }
- public void deleteUser(Inscription user) {
- SQLiteDatabase db = this.getWritableDatabase();
- // delete user record by id
- db.delete(TABLE_NAME, COLUMN_ID + " = ?",
- new String[]{String.valueOf(user.getId())});
- db.close();
- }
- public boolean checkInscris(String phone) {
- // array of columns to fetch
- String[] columns = {
- COLUMN_ID
- };
- SQLiteDatabase db = this.getReadableDatabase();
- // selection criteria
- String selection = COLUMN_PHONE + " = ?";
- // selection argument
- String[] selectionArgs = {phone};
- // query user table with condition
- /**
- * Here query function is used to fetch records from user table this function works like we use sql query.
- * SQL query equivalent to this query function is
- * SELECT user_id FROM user WHERE user_email = '[email protected]';
- */
- Cursor cursor = db.query(TABLE_NAME, //Table to query
- columns, //columns to return
- selection, //columns for the WHERE clause
- selectionArgs, //The values for the WHERE clause
- null, //group the rows
- null, //filter by row groups
- null); //The sort order
- int cursorCount = cursor.getCount();
- cursor.close();
- db.close();
- if (cursorCount > 0) {
- return true;
- }
- return false;
- }
- public boolean checkInscris(String pseudo, String phone) {
- // array of columns to fetch
- String[] columns = {
- COLUMN_ID
- };
- SQLiteDatabase db = this.getReadableDatabase();
- // selection criteria
- String selection = COLUMN_PSEUDO + " = ?" + " AND " + COLUMN_PHONE + " = ?";
- // selection arguments
- String[] selectionArgs = {pseudo, phone};
- // query user table with conditions
- /**
- * Here query function is used to fetch records from user table this function works like we use sql query.
- * SQL query equivalent to this query function is
- * SELECT user_id FROM user WHERE user_email = '[email protected]' AND user_password = 'qwerty';
- */
- Cursor cursor = db.query(TABLE_NAME, //Table to query
- columns, //columns to return
- selection, //columns for the WHERE clause
- selectionArgs, //The values for the WHERE clause
- null, //group the rows
- null, //filter by row groups
- null); //The sort order
- int cursorCount = cursor.getCount();
- cursor.close();
- if (cursorCount > 0) {
- return true;
- }
- db.close();
- return false;
- }
Login.java.class: Manifest.xml: Thanks!
- public class login extends AppCompatActivity {
- DatabaseHelper myDb;
- EditText TextPseudo,Textphone;
- Button blogin;
- View v;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_login);
- TextPseudo=(EditText)findViewById(R.id.editTextPseudo) ;
- Textphone=(EditText)findViewById(R.id.input_phone);
- blogin=(Button)findViewById(R.id.buttonlogin);
- v=findViewById(android.R.id.content);
- blogin.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- switch (view .getId()) {
- case R.id.buttonlogin:
- verifyFromSQLite();
- break;
- case R.id.linkSignup:
- // Navigate to RegisterActivity
- Intent intentRegister = new Intent(getApplicationContext(), register.class);
- startActivity(intentRegister);
- break;
- }
- }
- private void verifyFromSQLite() {
- if (myDb.checkInscris(TextPseudo.getText().toString().trim()
- , Textphone.getText().toString().trim())) {
- Intent accountsIntent = new Intent(getApplicationContext(), Menu.class);
- accountsIntent.putExtra("phone", Textphone.getText().toString().trim());
- emptyInputEditText();
- startActivity(accountsIntent);
- } else {
- // Snack Bar to show success message that record is wrong
- Snackbar.make( v,"Pseudo et téléphone incorrect", Snackbar.LENGTH_LONG).show();
- }
- }
- private void emptyInputEditText() {
- TextPseudo.setText(null);
- Textphone.setText(null);
- }
- });
- }
- xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.example.sofari.tiffanezni">
- <uses-permission android:name="android.permission.CAMERA" />
- <uses-feature android:name="android.hardware.camera" />
- <uses-feature android:name="android.hardware.camera.autofocus" />
- <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
- <uses-sdk
- android:minSdkVersion="7"
- android:targetSdkVersion="16" />
- <application
- android:allowBackup="true"
- android:icon="@drawable/ic_tiffa"
- android:label="@string/app_name"
- android:roundIcon="@drawable/ic_tiffa"
- android:supportsRtl="true"
- android:theme="@style/AppTheme">
- <activity android:name=".MainActivity">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- intent-filter>
- activity>
- <activity android:name=".login"
- android:label="Login">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.DEFAULT" />
- intent-filter>
- activity>
- <activity android:name=".register"
- android:label="Inscription">
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.DEFAULT" />
- intent-filter>
- activity>
- <activity android:name=".Menu"
- android:label="Menu">activity>
- application>
- manifest>

Sofari AgaliPosted Sep 27, 2017, 1:16 PM
Mukil VendhanPosted Sep 27, 2017, 11:15 AM