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 9125375
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:47:23+00:00 2026-06-17T06:47:23+00:00

I am trying to implement a ListView with test values. It should display 2

  • 0

I am trying to implement a ListView with test values. It should display 2 strings per list element. But i get a NullPointerException.

I have a ListActivity, calling an Adapter. If I comment the last line of this activity, I don’t have any error so I guess that my adaptator has something wrong. But I have searched solutions on the Web, and unfortunatelly, I cannot solve my problem due to a very low Java (and OOP) skill. Can you please tell me where I mad a mistake ?

public class ListActivity extends Activity {

//private final String TAG = ListActivity.class.getSimpleName();
private ListView listMessView;

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

    List<Message> listMessages = new ArrayList<Message>();
    listMessages.add(new Message("London", "aze"));
    listMessages.add(new Message("Rome", "azeeaze"));
    listMessages.add(new Message("Paris", "qsdqsdqsd"));

    listMessView =  (ListView) findViewById(R.id.message_list);
    listMessView.setAdapter(new ListAdaptater(this, R.layout.list_row, listMessages));
    }
}


public class ListAdaptater extends ArrayAdapter<Message>{

  private int resource;
  private LayoutInflater inflater;
  private Context context;

  public ListAdaptater ( Context ctx, int resourceId, List<Message> objects) {

        super( ctx, resourceId, objects );
        resource = resourceId;
        inflater = LayoutInflater.from( context );
        context=ctx;
  }

  @Override
  public View getView ( int position, View convertView, ViewGroup parent ) {

        convertView = ( RelativeLayout ) inflater.inflate( resource, null );

        Message message = (Message) getItem( position );

        TextView txtName = (TextView) convertView.findViewById(R.id.user_name);
        txtName.setText(message.getUserName());

        TextView txtMsg = (TextView) convertView.findViewById(R.id.message);
        txtMsg.setText(message.getMessage());

        return convertView;
  }
  }
  • 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-17T06:47:24+00:00Added an answer on June 17, 2026 at 6:47 am

    The field context is used before it’s initialized. Try using this:

      public ListAdaptater ( Context ctx, int resourceId, List<Message> objects) {
    
            super( ctx, resourceId, objects );
            resource = resourceId;
            inflater = LayoutInflater.from( ctx );
            context=ctx;
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a customized ListView, that should display a note title and
I'm trying to implement a list using the ListView, which contains rows built with
I'm trying to implement a ListView on my app, but i'm trying to understand
Check: I am trying to implement filter on my ListView . But I am
I'm trying to implement flowtextview into bauerca / drag-sort-listview but I'm getting an error
I am trying to implement list. Here is start.xml file which have a text
I'm trying to implement OnListItemClick but can't seem to get it working. There are
I'm trying to implement a listView with EditText Controls. Problem is when I edit
i am trying to implement listbox (or listview): <ListView ItemsSource={Binding Players} SelectedIndex={Binding SelectedIndex}> My
Trying to implement LoaderManager + CursorLoader. In onFinish method adapter should swap its cursor

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.