2017-02-13 104 views
1
package com.thenweboston.zaika; 

import android.app.Activity; 
import android.database.Cursor; 
import android.database.sqlite.SQLiteDatabase; 
import android.os.Bundle; 
import android.text.TextUtils; 
import android.view.View; 
import android.widget.Button; 
import android.widget.EditText; 
import android.widget.TextView; 
import android.widget.Toast; 


public class Fourth extends Activity 
{ 
    private EditText ed1,ed2; 
    private Button b; 
    private TextView tv; 
    private SQLiteDatabase db; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) 
    { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.login); 
      ed1=(EditText)findViewById(R.id.EditTxt); 
      ed2=(EditText)findViewById(R.id.EditTxt1); 
      b=(Button)findViewById(R.id.button5); 
      tv=(TextView)findViewById(R.id.txtView); 
      b.setOnClickListener(new View.OnClickListener() 
      { 
       public void onClick(View v) 
       { 
        String s=ed1.getText().toString(); 
        String y=ed2.getText().toString(); 
        if(TextUtils.isEmpty(s)) 
        { 
         ed1.setError("Please fill your username"); 
        } 
        else if(TextUtils.isEmpty(y)) 
        { 
         ed2.setError("Please fill your password"); 
        } 
        else 
        { 
         check(); 
        } 
       } 
      }); 
     } 
    public void check() 
    { 
      db=SQLiteDatabase.openDatabase("/data/com.thenweboston.zaika/databases/Hotels",null,SQLiteDatabase.OPEN_READONLY); 
     String query="Select * from hot where email='s' and password='y'"; 
     Cursor c=db.rawQuery(query,null); 
     if(c.getCount()>0) 
     Toast.makeText(getApplicationContext(),"true",Toast.LENGTH_SHORT); 
     else 
      Toast.makeText(getApplicationContext(),"wrong credentials",Toast.LENGTH_SHORT).show(); 
    } 
} 

我想创建一个登录页面,它不会允许具有错误凭据的用户访问主页。在这里试图运行代码时,我得到“数据库无法打开”异常。数据库无法打开异常

回答

-1

// Android的应用程序数据库的默认系统路径。

private static String DB_PATH = "/data/data/YOUR_PACKAGE/databases/";