2017-02-13 9 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/"; 
関連する問題