数据库无法打开异常

时间:2017-02-13 14:14:01

标签: android sqlite exception-handling

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();
    }
}

我正在尝试创建一个登录页面,它不允许具有错误凭据的用户访问主页。当我尝试运行我正在获取的代码时,#34;数据库无法访问打开"异常。

1 个答案:

答案 0 :(得分:-1)

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

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