Gamesroom Iran Gamesroom Iran - 4 months ago 53
Android Question

Why null text set in adapter?

I'm confused on this problem!

I set text to

in adapter, but when my listview is generated, TextView is null yet.

My problem is about
because when i put text manually it works perfectly.

Please help me.

This is my "Adapter" :

package ir.sarashpazp.peymanehsarashpaz;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

public class MainAdapter extends BaseAdapter {
private Activity activity;
private LayoutInflater inflater;
private List<items> feedItems;
private items item;

public MainAdapter(Activity activity, List<items> feedItems) {
this.activity = activity;
this.feedItems = feedItems;

public int getCount() {
return feedItems.size();

public Object getItem(int location) {
return feedItems.get(location);

public long getItemId(int position) {
return position;

public View getView(int position, View convertView, ViewGroup parent) {
item = new items();
if (inflater == null)
inflater = (LayoutInflater) activity
if (convertView == null)
convertView = inflater.inflate(R.layout.eachdastoor, null);

TextView name = (TextView) convertView.findViewById(;


return convertView;


This is my "items" class :

public class items {
private int id;
private String name, status, image, profilePic, timeStamp, url;

public items() {

public items(int id, String name, String image, String status,
String profilePic, String timeStamp, String url) {
super(); = id; = name;
this.image = image;
this.status = status;
this.profilePic = profilePic;
this.timeStamp = timeStamp;
this.url = url;

public int getId() {
return id;

public void setId(int id) { = id;

public String getName() {
return name;

public void setName(String name) { = name;



You are always accessing a new object instance instead of an item of you array. Please replace

 item = new items(); 


 item = feedItems.get(position);