Skip to content Skip to sidebar Skip to footer

Android Parse.com Populate Listview With Custom Adapter Issue

I am receiving a NullPointerException when retreiving data from parse.com. I have traced through the program and I am indeed receiving data. I will copy in my source code for the a

Solution 1:

You are doing mistake in view assigning So you must follow this custom adapter it will help you definitely All the Best....

publicclassCustomAdapterextendsArrayAdapter<Sample> {

public ArrayList<Sample> mlist;
public Context context;
public LayoutInflater inflater;

publicCustomAdapter(Context context, int resource, ArrayList<Sample> mlist) {
super(context, resource);
this.mlist = mlist;
this.context = context;
inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}

@OverridepublicintgetPosition(Sample item) {
returnsuper.getPosition(item);
}

@Overridepublic Sample getItem(int position) {
return mlist.get(position);
}

@OverridepublicintgetCount() {
return mlist.size();
}

@OverridepubliclonggetItemId(int position) {
returnsuper.getItemId(position);
}

@Overridepublic View getView(int position, View convertView, ViewGroup parent) {
convertView = inflater.inflate(R.layout.listitem, null);//Replace your layout....TextViewtext1= (TextView) convertView.findViewById(R.id.item1);
TextViewtext2= (TextView) convertView.findViewById(R.id.item2);
text1.setText(mlist.get(position).getListitem1());
text2.setText(mlist.get(position).getListitem2());
text2.setOnClickListener(newOnClickListener() {
    @OverridepublicvoidonClick(View v) {
        // you just put your Logic here And use this custom adapter to// load your Data By using this particular custom adapter to// your listview//Change your imageview here

    }
});
return convertView;
}

}

Solution 2:

You are using your own "List chat" instead of the array provided by ArrayAdapter. In this case, you need to initialise the chat reference with an object (Java won't do it automatically). Without doing this, 'chat' points to a null/junk instance and doing chat.add() will throw a NullPointerException.

In your GroupChatAdapter constructer, add this line: chat = new List ();

The other option you have is to use the default list provided by ArrayAdapter. In this case, delete you chat object definition and the add(GroupChat) function definition. The adapter provides and add function automatically, which you can use the same way as you are doing in onCreate().

Post a Comment for "Android Parse.com Populate Listview With Custom Adapter Issue"