Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9150951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:40:59+00:00 2026-06-17T11:40:59+00:00

Reason why I think it is happening: I am guessing I implemented my custom

  • 0

Reason why I think it is happening:

I am guessing I implemented my custom ArrayAdapter incorrectly or I am querying incorrectly for the ListView

Error:

01-17 15:49:56.775: E/AndroidRuntime(531): FATAL EXCEPTION: main
01-17 15:49:56.775: E/AndroidRuntime(531): java.lang.NullPointerException
01-17 15:49:56.775: E/AndroidRuntime(531):  at com.gannett.democratandchronicle.billstrainingcamp.EventAdapter.getView(EventAdapter.java:45)

ScheduleActivity.java

package com.gannett.democratandchronicle.billstrainingcamp;
import java.util.ArrayList;
import java.util.Date;

import android.os.Bundle;
import android.widget.ListView;

public class ScheduleActivity extends BillsCampActivity 
{
    private EventAdapter ea;

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

        Event e1 = new Event("Test 1", new Date(), "Desc");
        Event e2 = new Event("Test 2", new Date(), "Desc");
        Event e3 = new Event("Test 3", new Date(), "Desc");
        Event e4 = new Event("Test 4", new Date(), "Desc");

        ArrayList<Event> schedule = new ArrayList<Event>();
        schedule.add(e1);
        schedule.add(e2);
        schedule.add(e3);
        schedule.add(e4);
        ea = new EventAdapter(this, R.layout.event_item, schedule);
        ListView listView = (ListView)this.findViewById(R.id.schedule_list_view);
        listView.setAdapter(ea);
    }

}

activity_schedule.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="fill_parent" >
    <ListView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent" 
        android:id="@+id/schedule_list_view"
        >
    </ListView>
</LinearLayout>

EventAdapter.java

package com.gannett.democratandchronicle.billstrainingcamp;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

public class EventAdapter extends ArrayAdapter<Event> 
{
    private int resource;

    public EventAdapter(Context context, int textViewResourceId,
            List<Event> objects) 
    {
        super(context, textViewResourceId, objects);
        this.resource = textViewResourceId;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
        View eventItemView;
        if (convertView == null)
        {
            eventItemView = new LinearLayout(getContext());
            LayoutInflater li = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            li.inflate(resource, null);
        }
        else
        {
            eventItemView = (LinearLayout)convertView;
        }

        TextView eventName = (TextView)eventItemView.findViewById(R.id.eventName);
        TextView eventDate = (TextView)eventItemView.findViewById(R.id.eventDate);

        Event e = this.getItem(position);

        eventName.setText(e.toString());
        eventDate.setText(e.getDate().toString());
        return eventItemView;
    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:41:00+00:00Added an answer on June 17, 2026 at 11:41 am

    The first mistake I see is on EventAdapter.java, where you create a new LinearLayout because it should come from the inflate call. The getView should look like this:

    @Override
    public View getView(int position, View convertView, ViewGroup parent) 
    {
        View eventItemView = convertView;
        if (eventItemView == null)
        {
            LayoutInflater li = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            eventItemView = li.inflate(resource, false);
        }
    
        TextView eventName = (TextView)eventItemView.findViewById(R.id.eventName);
        TextView eventDate = (TextView)eventItemView.findViewById(R.id.eventDate);
    
        Event e = this.getItem(position);
    
        eventName.setText(e.toString());
        eventDate.setText(e.getDate().toString());
        return eventItemView;
    }
    

    Then, on the layout XML you don’t define the TextView for eventName and eventDate, so you might get a resource not found exception later. The activity_schedule.xml should be like:

    <?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="fill_parent" >
        <ListView xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent" 
            android:id="@+id/schedule_list_view" >
            <TextView
            android:id="@+id/eventName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
            <TextView
            android:id="@+id/eventDate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />
        </ListView>
    </LinearLayout>
    

    Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, subversion is returning me error messages in what I think is
Is there ever reason to think the >> (signed) and >>> (unsigned) right bit-shift
for some reason (and I think I know why), when more than one row
I cant really think of a reason it wouldnt...it looks fine to me (if
I think there is a simple answer to this, but for some reason I
I think it should be 01 but someone says its undefined, any reason for
I think I'm missing something really obvious here... must be... but for some reason
For some reason, after installing and configuring (I think) everything, the com.adobe.utils.AGALMiniAssembler is missing,
For some reason, I'm getting this error message: Uncaught SyntaxError: Unexpected token < For
I have found that one common reason for the error is an exception being

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.