私はアプリを持っています。初めてログインするか登録します。sqliteデータベースを使用しています。私はオンラインで何も見つけられませんでした 私の問題はアプリのログをクリックするとシャットダウンされます ここボタンをクリックするたびにAndroidアプリがシャットダウンします
package com.example.i.projet;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class loginActivity extends AppCompatActivity {
BaseDeDonee bdd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final EditText lemail =(EditText) findViewById(R.id.lemail);
final EditText lpassword =(EditText) findViewById(R.id.lpassword);
final Button sbotton=(Button) findViewById(R.id.sbutton);
final Button lbotton=(Button) findViewById(R.id.lbutton);
if (lemail.getText().toString()=="" || lpassword.getText() .toString()==""){
lemail.setError("email is required!");
lemail.setHint("please enter email");
}
sbotton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(loginActivity.this,regestryActivity.class);
startActivity(intent);
}
});
lbotton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (lemail.getText().toString()=="" || lpassword.getText() .toString()==""){
lemail.setError("email is required!");
lemail.setHint("please enter email");
}else {
boolean ress =bdd.finde(lemail.getText().toString(),lpassword.getText().toString());
if (ress==true){
Intent intent = new Intent(loginActivity.this,MainActivity.class);
startActivity(intent);
}
else Toast.makeText(loginActivity.this, "wrong dont exist", Toast.LENGTH_LONG).show();
}
}
});
}
}
とデータベースクラス
package com.example.i.projet;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class BaseDeDonee extends SQLiteOpenHelper {
public static final String DATABASE_NAME = "Platforme.db";
public static final String TABLE_PERSONNE = "UsersTable";
public static final String COL_1 = "ID";
public static final String COL_2 = "nom";
public static final String COL_3 = "prenom";
public static final String COL_4 = "numero_tel";
public static final String COL_5 = "profile";
public static final String COL_s = "password";
public static final String COL_k = "etat";
public static final String TABLE_COMPTE = "CompteTable";
public static final String COL_6 = "numero_compte";
public static final String COL_7 = "cle_compte";
public static final String COL_8 = "solde_courante";
public static final String COL_9 = "type_compte";
public static final String TABLE_OPPERATIONS = "OpperationsTable";
public static final String COL_10 = "num_opp";
public static final String COL_11 = "type_opp";
public static final String COL_12 = "date_opp";
public static final String COL_13 = "montant_opp";
public static final String COL_14 = "solde_courante";
//+etat de l'opp pour avoir est que personel ou du busness
public static final String TABLE_PRODUITS = "ProductsTable";
public static final String COL_15 = "nom_prod";
public static final String COL_16 = "type_prod";
public static final String COL_17 = "PrixUnit_prod";
public static final String COL_18 = "quantite_prod";
public static final String COL_19 = "PrixTotal_prod";
public static final String TABLE_FACTURES = "FacturesTable";
public static final String COL_20 = "num_fact";
public static final String COL_21 = "type_fact";
public static final String COL_22 = "Montant_fact";
public static final String COL_23 = "date_fact";
public static final String TABLE_IDENTIFICATION = "IdentificationTable";
public static final String COL_24 = "profile";
public static final String COL_25 = "password";
public static final String TABLE_DECAISSEMENT = "DecaissementTable";
public static final String COL_26 = "num_opp";
public static final String COL_27 = "type_compte";
public static final String COL_28 = "piecejustificatif";
public static final String TABLE_Temp = "tempTable";
public BaseDeDonee(Context context) {
super(context, DATABASE_NAME, null, 1);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create table " + TABLE_PERSONNE +" (ID INTEGER PRIMARY KEY AUTOINCREMENT,nom TEXT,prenom TEXT,numero_tel INTEGER,profile TEXT,password Text,etat Text)");
db.execSQL("create table " + TABLE_COMPTE +" (numero_compte INTEGER PRIMARY KEY,cle_compte INTEGER,solde_courante DOUBLE,type_compte TEXT,ID INTEGER REFERENCES TABLE_PERSONNE)");
db.execSQL("create table " + TABLE_PRODUITS +" (nom_prod TEXT PRIMARY KEY,type_prod TEXT,PrixUnit_prod DOUBLE,quantite_prod INTEGER,PrixTotal_prod DOUBLE,num_opp INTEGER REFERENCES TABLE_OPPERATIONS)");
db.execSQL("create table " + TABLE_FACTURES +" (num_fact INTEGER PRIMARY KEY AUTOINCREMENT,type_fact TEXT,Montant_fact DOUBLE,date_fact DATE,num_opp INTEGER REFERENCES TABLE_OPPERATIONS,ID INTEGER REFERENCES TABLE_PERSONNE)");
db.execSQL("create table " + TABLE_OPPERATIONS +" (num_opp INTEGER PRIMARY KEY AUTOINCREMENT,type_opp TEXT,montant_opp DOUBLE,date_opp DATE,ID INTEGER REFERENCES TABLE_PERSONNE ,solde_courante DOUBLE REFERENCES TABLE_COMPTE)");
db.execSQL("create table " + TABLE_IDENTIFICATION +" (profile TEXT REFERENCES TABLE_PERSONNE PRIMARY KEY ,password TEXT REFERENCES TABLE_PERSONNE)");
db.execSQL("create table " + TABLE_DECAISSEMENT + " (piecejustificatif TEXT PRIMARY KEY,num_opp INTEGER REFERENCES TABLE_OPPERATIONS,type_compte TEXT REFERENCES TABLE_COMPTE)");
db.execSQL("create table " + TABLE_Temp + " (ID INTEGER PRIMARY KEY REFERENCES TABLE_PERSONNE)");
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("DROP TABLE IF EXISTS "+TABLE_PERSONNE+TABLE_COMPTE+TABLE_PRODUITS+TABLE_FACTURES+TABLE_OPPERATIONS+TABLE_IDENTIFICATION+TABLE_DECAISSEMENT+TABLE_Temp);
onCreate(db);
}
public boolean insertData(String nom ,String prenom ,String tel,String profile,String password ,String etat){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues contentValues = new ContentValues();
Cursor res = db.query(TABLE_PERSONNE,new String[]{"*"},"profile =?",new String[]{profile},null,null,null);
contentValues.put(COL_2,nom);
contentValues.put(COL_3,prenom);
contentValues.put(COL_4,tel);
contentValues.put(COL_5,profile);
contentValues.put(COL_s,password);
contentValues.put(COL_k,etat);
if(res!=null && res.moveToFirst()){
return false;
}else{
long result= db.insert(TABLE_PERSONNE, null, contentValues);
if (result==-1){
return false;
}else return true; }
}
public boolean insertl(String profile ,String password){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues ContentVlues = new ContentValues();
ContentVlues.put(COL_24,profile);
ContentVlues.put(COL_25,password);
long result =db.insert(TABLE_IDENTIFICATION,null,ContentVlues);
if (result==-1)
return false;
else return true ;
}
public boolean insertfacture(String type ,String Montantfact, String date){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues ContentVlues = new ContentValues();
ContentVlues.put(COL_21,type);
ContentVlues.put(COL_22,Montantfact);
ContentVlues.put(COL_23,date);
long result =db.insert(TABLE_FACTURES,null,ContentVlues);
if (result==-1)
return false;
else return true ;
}
public boolean insertCompte(String numero_compte ,String cle_compte, String solde_courante,String type_compte){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues ContentVlues = new ContentValues();
ContentVlues.put(COL_6,numero_compte);
ContentVlues.put(COL_7,cle_compte);
ContentVlues.put(COL_8,solde_courante);
ContentVlues.put(COL_9,type_compte);
long result =db.insert(TABLE_COMPTE,null,ContentVlues);
if (result==-1)
return false;
else return true ;
}
public boolean insertProduit(String nom_prod ,String type_prod, String PrixUnit_prod,String quantite_prod,String PrixTotal_prod){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues ContentVlues = new ContentValues();
ContentVlues.put(COL_15,nom_prod);
ContentVlues.put(COL_16,type_prod);
ContentVlues.put(COL_17,PrixUnit_prod);
ContentVlues.put(COL_18,quantite_prod);
ContentVlues.put(COL_19,PrixTotal_prod);
long result =db.insert(TABLE_PRODUITS,null,ContentVlues);
if (result==-1)
return false;
else return true ;
}
public boolean inseloginid(int id ){
SQLiteDatabase db = this.getWritableDatabase();
ContentValues ContentVlues = new ContentValues();
ContentVlues.put(COL_1,id);
long result =db.insert(TABLE_Temp,null,ContentVlues);
if (result==-1)
return false;
else return true ;
}
public Cursor afficherinfoP(){
SQLiteDatabase db = this.getWritableDatabase();
Cursor res = db.rawQuery("select * from "+TABLE_PERSONNE,null);
return res;
}
public Boolean finde(String lemail, String lpass) {
SQLiteDatabase db = this.getWritableDatabase();
Cursor res = db.query(TABLE_IDENTIFICATION, null, "profile=? AND password=?",new String[]{lemail,lpass},null,null,null);
if(res!=null && res.moveToFirst()){
res.close();
return false;
}else {
res.close();
return true;
}
}
public int findID (String lemail){
SQLiteDatabase db = this.getWritableDatabase();
Cursor res = db.rawQuery("select 'id' from "+TABLE_PERSONNE+"where 'profile'="+lemail,null);
int k = res.getInt(res.getColumnIndex("id"));
return k;
}
public int tempID(){
SQLiteDatabase db = this.getWritableDatabase();
Cursor res = db.rawQuery("select * from "+TABLE_Temp,null);
int k = res.getInt(res.getColumnIndex("id"));
return k ;
}
public double rapportJ(String date,int id){
Double k= Double.valueOf(0);
SQLiteDatabase db = this.getWritableDatabase();
Cursor res = db.rawQuery("Select * from"+TABLE_FACTURES+"where date_fact="+date+"and id="+id,null);
while (res.moveToNext()){
k=k+ res.getDouble(2);
}
Cursor ress=db.rawQuery("Select * from"+TABLE_OPPERATIONS+"where date_opp="+date+"and id="+id,null);
while (ress.moveToNext()){
k=k+ ress.getDouble(2);
}
return k;
}
}
0123:関数でありますlemailまたはlpasswordいずれかが空のようスタックトレースenter image description here
あなたstackrace – bubunyo
を投稿することができ、私はそれを追加して、ログインjavaの39はラインbooleenのRESSある= ..... –
は 'lemail'と' lpassword'です!= 'null'なので? – user0815