W / SQLiteConnectionPool:数据库ERROR的SQLiteConnection对象

时间:2017-10-30 06:02:27

标签: android android-sqlite

我正在尝试使用SQLite数据库来存储我的应用程序的用户凭据数据

每当我尝试调试我的应用程序时,我总是在Debug LOGCAT中收到这些警告,因为我的应用程序停止运行并关闭

以下是我收到的警告

10-30 10:59:49.421 5435-5444/? W/SQLiteConnectionPool: A SQLiteConnection 
object fordatabase'/data/user/0/com.google.android.gms/databases/metrics.db' 
was leaked!

10-30 10:59:49.474 5435-5444/? W/SQLiteConnectionPool: A SQLiteConnection 
 object for database 
'/data/user/0/com.google.android.gms/databases/help_responses.db.18'

这是我的DBHelper类

 public class DbHelper extends SQLiteOpenHelper {


public DbHelper(Context context) {
    super(context, "UserCredentials.db", null, 1);
}

@Override
public void onCreate(SQLiteDatabase sqLiteDatabase) {

    sqLiteDatabase.execSQL("create table UserInfo (User_Name text,Email text,Password text,Mobile text);");
}

@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1) {

    sqLiteDatabase.execSQL("drop table if exists UserInfo");
    onCreate(sqLiteDatabase);

  }
 }

这是我的loginform类(此类用于与应用程序一起演唱)

public class LogInForm extends AppCompatActivity  {



private String UserName,EmailID,Password,PhoneNum;
private Date Birth;
private EditText userName,emailID,password,phoneNum,birth;
private Date date;
int Flag ;
DbHelper Db = new DbHelper(getApplicationContext());







protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.registration_form);
    Toolbar t2 = (Toolbar) findViewById(R.id.toolbarR) ;
    setSupportActionBar(t2);
    getSupportActionBar().setDisplayShowTitleEnabled(false);




      userName =  (EditText) findViewById(R.id.editTextUE);
      emailID  =  (EditText) findViewById(R.id.editTextEE);
      password =  (EditText) findViewById(R.id.editTextPE);
      phoneNum =  (EditText) findViewById(R.id.editTextPHE);
      birth    =  (EditText) findViewById(R.id.editTextDE);
      Button Register   =   (Button) findViewById(R.id.Register);


  Register.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View view) {
      initialize();
          SQLiteDatabase db = Db.getWritableDatabase();
          ContentValues values = new ContentValues();
          try{
              if(validate())
              {




                  values.put("User_Name", UserName);
                  values.put("Email", EmailID);
                  values.put("Password",Password);
                  values.put("Mobile",PhoneNum);

                  long row = db.insert("UserInfo", null, values);


                  Intent next = new Intent(getApplicationContext(),Success.class);
                  startActivity(next);
              }

          }
          finally {
              values.clear();
              db.close();

          }



      }



  });

}



public void initialize()
{
    Flag=1;
    UserName = userName.getText().toString().trim();
    EmailID =  emailID.getText().toString().trim();
    PhoneNum = phoneNum.getText().toString().trim();
    Birth =    convertToDate(birth.getText().toString().trim());
    Password = password.getText().toString().trim();

}

public boolean validate()
{
    if(UserName.isEmpty())
    {
        Flag=0;
        userName.setError(" Username cannot be blank");
    }

    SQLiteDatabase rdb = Db.getReadableDatabase();
    Cursor c = rdb.query("UserInfo", null, null, null, null, null, null);

    while(c.moveToNext()) {
        String value = c.getString(c.getColumnIndex("User_Name"));

        if ((value).equals(UserName))
        {
            Flag=0;
            userName.setError(" Username Exists");



        }
    }
    rdb.close();
    c.close();

   if(EmailID.isEmpty() || !android.util.Patterns.EMAIL_ADDRESS.matcher(EmailID).matches())
    {
        emailID.setError("Invalid EmailID");
        Flag=0;
    }
    if(Password.length() < 9 )
    {
        password.setError("Password must be more than 9 characters");
        Flag=0;
    }
     if(PhoneNum.isEmpty() || phoneNum.length()!=10)
    {
        phoneNum.setError("please enter valid phone Number");
        Flag=0;
    }

    if(Flag==0)
    {
        return false;
    }
    else
    {
        return true;
    }



}

这是我的主java类(如果用户有通过此类登录的帐户)

public class First extends AppCompatActivity {
DbHelper Db = new DbHelper(this);
EditText UserName = (EditText) findViewById(R.id.editText4);
EditText Password = (EditText) findViewById(R.id.editText5);
int Flag = 0;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.first);
    Toolbar t = (Toolbar) findViewById(R.id.toolbarL) ;
    setSupportActionBar(t);
    getSupportActionBar().setDisplayShowTitleEnabled(false);
    Button RegButton = (Button) findViewById(R.id.RegisterButton);
    Button  logButton = (Button) findViewById(R.id.LogButton);


    RegButton.setOnClickListener(new OnClickListener(){
        public void onClick(View view) {
            Intent i2 = new Intent(getApplicationContext(), LogInForm.class);

            startActivity(i2);
        }
    });

    logButton.setOnClickListener(new OnClickListener(){
        public void onClick(View view) {
           SQLiteDatabase sq = Db.getReadableDatabase();

            Cursor c = sq.query("UserInfo", null, null, null, null, null, null);

            while(c.moveToNext())
            {
              if(c.getString(0).equals(UserName.getText().toString())&& c.getString(2).equals(Password.getText().toString()))
              {
                  Flag = 1;
                  sq.close();
                  c.close();
                  Intent i3 = new Intent(getApplicationContext(), HomeScreen.class);
                  startActivity(i3);

              }
            }

            if(Flag==0)
            {
                Toast toast = Toast.makeText(getApplicationContext(),"INVALID UserName/Password",Toast.LENGTH_SHORT);
                toast.show();
                sq.close();
                c.close();
            }


        }
    });

}

} 我该如何解决这个问题?

0 个答案:

没有答案