Q:

I'm getting these Listview errors that crash my app

On building a page where users will send each other messages on my android app and I'm using a listview to display all the messages sent or receive. For the initial test, I tried to send myself a message but it crashes the app and the error messages puzzle me. It says
07-17 02:38:26.847: E/AndroidRuntime(2581): FATAL EXCEPTION: main
07-17 02:38:26.847: E/AndroidRuntime(2581): java.lang.NullPointerException
07-17 02:38:26.847: E/AndroidRuntime(2581):     at android.widget.SimpleAdapter.getCount(SimpleAdapter.java:93)
07-17 02:38:26.847: E/AndroidRuntime(2581):     at android.widget.ListView.setAdapter(ListView.java:460)
07-17 02:38:26.847: E/AndroidRuntime(2581):     at android.app.ListActivity.setListAdapter(ListActivity.java:265)
07-17 02:38:26.847: E/AndroidRuntime(2581):     at com.example.reflaptry1.SendMessage$1.onClick(SendMessage.java:39)
07-17 02:38:26.847: E/AndroidRuntime(2581):     at android.view.View.performClick(View.java:4084)
07-17 02:38:26.847: E/AndroidRuntime(2581):     at android.view.View$PerformClick.run(View.java:16966)
07-17 02:38:26.847: E/AndroidRuntime(2581):     at android.os.Handler.handleCallback(Handler.java:615)
07-17 02:38:26.847: E/AndroidRuntime(2581):     at android.os.Handler.dispatchMessage(Handler.java:92)
07-17 02:38:26.847: E/AndroidRuntime(2581):     at android.os.Looper.loop(Looper.java:137)
07-17 02:38:26.847: E/AndroidRuntime(2581):     at android.app.ActivityThread.main(ActivityThread.java:4745)
07-17 02:38:26.847: E/AndroidRuntime(2581):     at java.lang.reflect.Method.invokeNative(Native Method)
07-17 02:38:26.847: E/AndroidRuntime(2581):     at java.lang.reflect.Method.invoke(Method.java:511)
07-17 02:38:26.847: E/AndroidRuntime(2581):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
07-17 02:38:26.847: E/AndroidRuntime(2581):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
07-17 02:38:26.847: E/AndroidRuntime(2581):     at dalvik.system.NativeStart.main(Native Method)

Here is what I have for the sendMessage class
import java.util.ArrayList;
import java.util.HashMap;

import android.app.ListActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListAdapter;
import android.widget.SimpleAdapter;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

public class SendMessage extends ListActivity {
    ArrayList<HashMap<String, String>> messageList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_send_message);

        Button sendText=(Button)findViewById(R.id.sendChat);
        sendText.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                EditText editMsg=(EditText)findViewById(R.id.theMessage);
                String msg=editMsg.getText().toString();
                HashMap<String, String> msgList=new HashMap<String, String>();
                msgList.put("yourMsg",msg);

                ListAdapter adapter= new SimpleAdapter(
                        SendMessage.this, messageList,
                        R.layout.list_message, new String[]{"yourMsg"},
                        new int[]{R.id.senderMessage});
                    setListAdapter(adapter);

            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.send_message, menu);
        return true;
    }

}

Here is my list_message.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >

    <!-- Product id (pid) - will be HIDDEN - used to pass to other activity -->
    <TextView
        android:id="@+id/pid"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:visibility="gone" />

    <!-- Name Label -->
    <TextView
        android:id="@+id/senderName"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingTop="16dip"
        android:paddingBottom="16dip"
        android:paddingLeft="16dip"

         />

    <TextView
        android:id="@+id/senderMessage"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
         />

</LinearLayout>

and my activity_send_message layout
<RelativeLayout 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"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".SendMessage" >

    <EditText
        android:id="@+id/theMessage"
        android:layout_width="220dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_marginBottom="15dp"
        android:ems="10"
        android:hint="@string/write" />

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="350dp"
        android:layout_above="@+id/theMessage"
        android:layout_alignLeft="@+id/theMessage"
        android:layout_marginBottom="14dp" >
    </ListView>

    <Button
        android:id="@+id/sendChat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/theMessage"
        android:layout_toRightOf="@+id/theMessage"
        android:text="@string/button_send" />

</RelativeLayout>

So yeah I don't really no what's going wrong.

A:

May this help you..
Constructor of SimpleAdapter takes List in argument 2 like : SimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to);
So, do like this to add value pair in Adapter:
List<HashMap<String, String>> aList = new ArrayList<HashMap<String, String>>();

    HashMap<String, String> hm = new HashMap<String, String>();
    HashMap<String, String> hm1 = new HashMap<String, String>();
    hm.put("Name","abc");
    hm1.put("Password","abc");
    aList.add(hm);

