mardi 30 juin 2015

IOException while trying to read the file

me and my friend are creating android application for our studies which works like KeePass.

The problem is that this application works on my friend phone with Android 4.0.3 and on my phone with Android 4.4.2 KitKat it doesn't. Why?

I can create database file with no exceptions, but when I try to log in it throws IOException. We think that this exception might be thrown by FileInputStream but we don't have any idea why.

Here is the code where the exception appears:

public void onClickLogon(View view){
    _db = null;
    FileInputStream fis = null;
    try {
        fis = openFileInput(this.login.getText().toString() + ".db");
        _db = (PasswordDatabase) com.example.tomus.passwordwalletbeta.Security.decrypt(fis, this.login.getText().toString(), this.password.getText().toString());
        fis.close();
        if(_db==null){
            this.info.setText("Wrong informations.");
        }
        else {
            Intent intent = new Intent(MainActivity.this, LoggedActivity.class);
            Bundle bundle = new Bundle();
            bundle.putSerializable("db", _db);
            bundle.putString("login", login.getText().toString());
            bundle.putString("password", password.getText().toString());
            intent.putExtras(bundle);
            this.login.setText("");
            this.password.setText("");
            startActivity(intent);
        }
    } catch (InvalidKeyException | NoSuchPaddingException | NoSuchAlgorithmException e) {
        this.info.setText("Wrong informations.");
    } catch (FileNotFoundException e) {
        this.info.setText("FileNotFound");
    } catch (IOException e) {
        this.info.setText("IOException");
    }
}

Aucun commentaire:

Enregistrer un commentaire