mardi 28 avril 2015

Not copied from BD assets

Not copied from BD assets.

On top of the Main app code. This is the code copy,

public class MainActivity extends Activity implements View.OnClickListener{
private EditText editTextLogin,editTextPassword;
private boolean admin=false;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    new CopyClass().copyDataBase(MainActivity.this, "test.db");
    new CopyClass().copyDataBase(MainActivity.this, "data.db");

    ((Button)findViewById(R.id.button)).setOnClickListener(this);
    ((Button)findViewById(R.id.button2)).setOnClickListener(this);
    editTextLogin= (EditText) findViewById(R.id.editText);
    editTextPassword= (EditText) findViewById(R.id.editText2);

}

I've tried a lot of things change but it does not work, and debiera tinkering this way and that. All of the useless. Each time fails. More precisely, the application crash

public void copyDataBase(final Context context, final String nameBD){
    try {
        //Открываем локальную БД как входящий поток
        InputStream myInput = context.getAssets().open(nameBD);
        //Открываем пустую базу данных как исходящий поток
        OutputStream myOutput = new FileOutputStream(context.getDatabasePath(nameBD));
        //перемещаем байты из входящего файла в исходящий
        byte[] buffer = new byte[1024];
        int length;
        while ((length = myInput.read(buffer)) > 0) {
            myOutput.write(buffer, 0, length);
        }
        //закрываем потоки
        myOutput.flush();
        myOutput.close();
        myInput.close();
    } catch (FileNotFoundException e) {e.printStackTrace();}
    catch (IOException e) {e.printStackTrace();}
}

In the Debugger, The application hangs on 20 seconds. After beginning to work, but in the folder /data/data/PROJ/databases/ No DB. May need in the Manifest to include something like write?

Aucun commentaire:

Enregistrer un commentaire