P
Paul2001
Guest
I want to implement a list view in my android application, even though the application is build without any errors, the emulator is constantly crashing with this code. After running the debugger I saw that the variable listview = findViewById(myPlantList); is set to null. Thus, I think that the problem is that the view with the ID "myPlantList" is not findable. ALthough the id is set correctly.
```
String names [] = {"Tomatoe", "Pepper Plant", "Big Tomatoe", "Small Tomatoe"};
ListView listview = findViewById(R.id.myPlantList);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, names);
listview.setAdapter(arrayAdapter);
```
Does anyone know how I should correctly find the ListView with the id myPlantList ?
```
String names [] = {"Tomatoe", "Pepper Plant", "Big Tomatoe", "Small Tomatoe"};
ListView listview = findViewById(R.id.myPlantList);
ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, names);
listview.setAdapter(arrayAdapter);
```
Does anyone know how I should correctly find the ListView with the id myPlantList ?