I have a task of inflating the view for the object a class called "ToDoItem" using a relative layout for this class named todo_item.xml .I have just started to learn android programming and i cant figure out why i am getting the following error.
java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.Resources android.content.Context.getResources()' on a null object reference
my code looks like this,there are more class specific functions but i have skipped them to make the problem code more visible.
public class ToDoListAdapter extends BaseAdapter {
private final List<ToDoItem> mItems = new ArrayList<ToDoItem>();
private final Context mContext;
LayoutInflater mInflater;
private static final String TAG = "Lab-UserInterface";
public ToDoListAdapter(Context context) {
mContext = context;
mInflater = LayoutInflater.from(context);
}// Create a View for the ToDoItem at specified position
// Remember to check whether convertView holds an already allocated View
// before created a new View.
// Consider using the ViewHolder pattern to make scrolling more efficient
// See: http://developer.android.com/training/improving-layouts/smooth- scrolling.html
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO - Get the current ToDoItem
final ToDoItem toDoItem = (ToDoItem) getItem(position);
// TODO - Inflate the View for this ToDoItem
// from todo_item.xml
convertView = mInflater.inflate(R.layout.todo_item,parent,false);
RelativeLayout itemLayout = (RelativeLayout) convertView.findViewById(R.id.RelativeLayout1);
// Fill in specific ToDoItem data
// Remember that the data that goes in this View
// corresponds to the user interface elements defined
// in the layout file
// TODO - Display Title in TextView
final TextView titleView = new TextView(null);
titleView.setText(toDoItem.getTitle());