Comment initialiser ArrayAdapter / Listview + vérifier sur

Pourquoi mon ArrayAdapter null? Entrer sur l'exception et quand je regarde le message, il m'a donné null. Je ne peux pas initialiser ce tableau. Je test mon string[] et ce n'est pas null. Je vois tous les noms de fichier à partir de mon mImageFilenames.

private void PopulateListView() {
mPrivateRootDir = new File(Environment.getExternalStorageDirectory()
+ "");
Toast.makeText(this, mPrivateRootDir + " <--mPrivateRootDir||",
Toast.LENGTH_LONG).show();
//Get the files/images subdirectory;
mImagesDir = new File(mPrivateRootDir, "MyPdf");
Toast.makeText(this, mImagesDir + "<--mImagesDir", Toast.LENGTH_LONG)
.show();
//Get the files in the images subdirectory
mImageFiles = mImagesDir.listFiles();
Toast.makeText(this, mImageFiles[0] + "<--mImageFiles||",
Toast.LENGTH_LONG).show();
//Set up ListView
listViewSelectFile = (ListView) findViewById(R.id.listviewSelectFiles);
//listViewSelectStudent = (ListView)
//findViewById(R.id.listviewSelectStudent);
/*
* Display the file names in the ListView mFileListView. Back the
* ListView with the array mImageFilenames, which you can create by
* iterating through mImageFiles and calling File.getAbsolutePath() for
* each File
*/
mImageFilenames = new String[mImageFiles.length];
for (int i = 0; i < mImageFilenames.length; ++i) {
mImageFilenames[i] = mImageFiles[i].getName();
Toast.makeText(this,
mImageFilenames[i] + "<-- mImageFilenames[i]" + " FOR",
Toast.LENGTH_LONG).show();
}
try {
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
R.layout.list_view_rows, R.id.listview, mImageFilenames);
listViewSelectFile.setAdapter(adapter);
//listViewSelectStudent.setAdapter(adapter);
} catch (Exception e) {
Toast.makeText(this, "ArrayAdapter Error :" + e.getMessage(),
Toast.LENGTH_LONG).show();
}

MODIFIER

screen3 xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false" >
<ListView
android:id="@+id/listviewSelectFiles"
android:layout_width="0dp"
android:layout_height="fill_parent"
android:layout_weight=".50" >
</ListView>
</LinearLayout>

list_view_rows xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/listviewSendFile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Send_Files"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
  • Exactement où êtes-vous d'obtenir de l'exception? Est-ce la première ligne du bloc try ou le second?
  • Sur la deuxième ligne, je reçois exception , sur la R. layout.list_view_rows contenir un textview sur le nom :listviewSendFile
  • Avez-vous vérifier ma réponse? Si elle contient un TextView, alors vous avez besoin de passer l'id de la place de la ListView.
InformationsquelleAutor user3411394 | 2014-03-16