java – how my app is not displaying datas in adapter?-ThrowExceptions

Exception or error:

i’m learning how to adapters and adapterViews on android. i wrote this code but when i run the app on my device, my app shows me a blank activity instead of this displaying the datas.

here is my java code:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    vue=(ListView)findViewById(R.id.listView);

    String[][]repertoire={{"Bill Gates","06 06 06 06 06"},{"Niels Bohr","05 05 05 05 05"},{"Alexande 
      III de Mac├ędoine","04 04 04 04 04"}};

    List<HashMap<String,String>> liste = new ArrayList<HashMap<String,String>>();

    HashMap<String,String> element;

    for(int i=0; i<repertoire.length; i++){
        element= new HashMap<String,String>();

        element.put("texte 1",repertoire[i][0]);
        element.put("texte 2",repertoire[i][1]);
    }

    ListAdapter adapter= new SimpleAdapter(this,liste,android.R.layout.simple_list_item_2,new 
                               String[]{"texte1","texte2"},new int[] {android.R.id.text1, 
                               android.R.id.text2 });

    vue.setAdapter(adapter);
}

and here is may XML file:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ListView
        android:id="@+id/listView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</LinearLayout>

and here is the result expected:

enter image description here

How to solve:

Leave a Reply

Your email address will not be published. Required fields are marked *