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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:18:44+00:00 2026-05-28T13:18:44+00:00

I’m trying to display data from my database in a ListFragment. To do this,

  • 0

I’m trying to display data from my database in a ListFragment. To do this, I have followed the same way when I use ListActivity, created my own adapter (adapter might look strange, I converted it from a class that extends BaseAdapter in one of my old projects):

package com.mysys.asistan;

import android.app.ListFragment;
import android.content.Context;
import android.database.DataSetObserver;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListAdapter;
import android.widget.TextView;

import com.mysys.asistan.database.Company;

public class CompanyListFragment extends ListFragment {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setListAdapter(new CompanyListAdapter(getActivity()));
    }

    private class CompanyListAdapter implements ListAdapter {

        private final Context context;
        private DatabaseHelper dbHelper;

        public CompanyListAdapter(Context context) {
            this.context = context;
            this.dbHelper = new DatabaseHelper(context);
        }

        public int getCount() {
            return dbHelper.getCompanyCount();
        }

        public Object getItem(int position) {
            return dbHelper.getAllCompanies().get(position);
        }

        public long getItemId(int position) {
            return (long) dbHelper.getAllCompanies().get(position).id;
        }

        public View getView(int position, View view, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View row = inflater.inflate(R.layout.company_list_item, parent, false);
            Company company = (Company) getItem(position);

            TextView nameView = (TextView) row.findViewById(R.id.CompanyListName);
            TextView telephoneView = (TextView) row.findViewById(R.id.CompanyListTelephone);
            TextView addressView = (TextView) row.findViewById(R.id.CompanyListAddress);

            nameView.setText(company.name);
            telephoneView.setText(company.telephone);
            addressView.setText(company.address);

            return null;
        }

        public int getItemViewType(int position) {
            return IGNORE_ITEM_VIEW_TYPE;
        }

        public int getViewTypeCount() {
            return 1;
        }

        public boolean hasStableIds() {
            return true;
        }

        public boolean isEmpty() {
            return getCount() == 0 ? true : false;
        }

        public void registerDataSetObserver(DataSetObserver observer) {
            // TODO Auto-generated method stub

        }

        public void unregisterDataSetObserver(DataSetObserver observer) {
            // TODO Auto-generated method stub

        }

        public boolean areAllItemsEnabled() {
            return true;
        }

        public boolean isEnabled(int position) {
            return true;
        }

    }
}

However, that leads to a NullPointerException and I couldn’t figure anything from the logs in LogCat, nothing related to my code:

01-24 20:24:06.040: E/AndroidRuntime(8731): FATAL EXCEPTION: main
01-24 20:24:06.040: E/AndroidRuntime(8731): java.lang.NullPointerException
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.widget.ListView.measureScrapChild(ListView.java:1181)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.widget.ListView.measureHeightOfChildren(ListView.java:1264)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.widget.ListView.onMeasure(ListView.java:1173)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.view.View.measure(View.java:10848)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4353)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.view.View.measure(View.java:10848)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4353)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.view.View.measure(View.java:10848)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4353)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1284)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.widget.LinearLayout.measureHorizontal(LinearLayout.java:956)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:521)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.view.View.measure(View.java:10848)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4353)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.view.View.measure(View.java:10848)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.widget.LinearLayout.measureVertical(LinearLayout.java:764)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.widget.LinearLayout.onMeasure(LinearLayout.java:519)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.view.View.measure(View.java:10848)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4353)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.widget.FrameLayout.onMeasure(FrameLayout.java:267)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2042)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.view.View.measure(View.java:10848)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.view.ViewRoot.performTraversals(ViewRoot.java:941)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.view.ViewRoot.handleMessage(ViewRoot.java:2063)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.os.Handler.dispatchMessage(Handler.java:99)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.os.Looper.loop(Looper.java:132)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at android.app.ActivityThread.main(ActivityThread.java:4126)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at java.lang.reflect.Method.invokeNative(Native Method)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at java.lang.reflect.Method.invoke(Method.java:491)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:844)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
01-24 20:24:06.040: E/AndroidRuntime(8731):     at dalvik.system.NativeStart.main(Native Method)

And this is the layout which contains the fragment:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <fragment
        android:id="@+id/fragment1"
        android:name="com.mysys.asistan.CompanyListFragment"
        android:layout_width="@dimen/company_listfragment_width"
        android:layout_height="wrap_content" />

</LinearLayout>

And this is company_list_item.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView android:id="@+id/CompanyListName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView android:id="@+id/CompanyListAddress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <TextView android:id="@+id/CompanyListTelephone"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</LinearLayout>

I found this question, but solution is not something related to my problem I think. Thanks in advance for your help.

  • 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-05-28T13:18:45+00:00Added an answer on May 28, 2026 at 1:18 pm

    You should return the view from getview() function. You are returning “Null”.

            public View getView(int position, View view, ViewGroup parent) {
            LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            View row = inflater.inflate(R.layout.company_list_item, parent, false);
            Company company = (Company) getItem(position);
    
            TextView nameView = (TextView) row.findViewById(R.id.CompanyListName);
            TextView telephoneView = (TextView) row.findViewById(R.id.CompanyListTelephone);
            TextView addressView = (TextView) row.findViewById(R.id.CompanyListAddress);
    
            nameView.setText(company.name);
            telephoneView.setText(company.telephone);
            addressView.setText(company.address);
    
            return row;//changed from null
        }
    

    Note: Use recycled view and Holders to make the listview scroll smooth. For beter understanding read this tutorial.

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

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Does anyone know how can I replace this 2 symbol below from the string

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.