Lire et écrire dans Documents
Bonjour a tous, voila j'ai un spinner et je voudrait que celui si afficher le contenue d'u fichier txt,
en le placent dans mon dossier d'application j'y arrive avec le code suivant:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
| if (android.os.Environment.getExternalStorageState().equals(
android.os.Environment.MEDIA_MOUNTED)) {
BufferedReader in = null;
try {
File sdLien = Environment.getExternalStorageDirectory();
in = new BufferedReader(new FileReader(sdLien + File.separator + "/android/data/ch.srvinfo.pr"
// in = new BufferedReader(new FileReader(sdLien + File.separator + "/Documents"
+ File.separator + "NomPr.txt"));
// File path = new File(Environment.getExternalStorageDirectory(),"/Documents/test/NomPr.txt");
// in = new BufferedReader(new FileReader(Environment.getExternalStorageDirectory(),"/Documents/test/NomPr.txt"));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
String str;
List<String> list = new ArrayList<String>();
try {
while ((str = in.readLine()) != null) {
list.add(str);
Log.d("Debug", String.valueOf(list));
}
} catch (IOException e) {
e.printStackTrace();
}
String[] stringArr = list.toArray(new String[0]);
//Ici l'autocomple
ArrayAdapter<CharSequence> adapter1 = new ArrayAdapter(this,
android.R.layout.simple_spinner_dropdown_item,
list);
AC_personne.setAdapter(adapter1);
} |
mais si je remplace la ligne:
Code:
in = new BufferedReader(new FileReader(sdLien + File.separator + "/android/data/ch.srvinfo.pr"
par:
Code:
in = new BufferedReader(new FileReader(sdLien + File.separator + "/Documents"
j'ai l'erreur Attempt to invoke virtual method 'java.lang.String java.io.BufferedReader.readLine()' on a null object reference
dans mon manifest jai bien rajouter les permission que je doit rajouter (de comme je comprends j'ai peut etre faux je ne sais pas:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ch.srvinfo.pr"
android:versionCode="1"
android:versionName="0.1 Alpha">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".accueil">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".settings" />
<activity android:name=".Contact" />
<activity android:name=".InfoInter" />
<activity android:name=".OpenInter" />
<activity android:name=".equipe" />
<activity android:name=".personne" />
<activity android:name=".popup1"></activity>
</application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNAL" />
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
</manifest> |
avez vous une idées d'ou viendrait mon problème?
Merci d'avance