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

  • Home
  • SEARCH
  • 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 7945407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:51:27+00:00 2026-06-04T00:51:27+00:00

I am trying to display a ListView from an ArrayList defined in the Application

  • 0

I am trying to display a ListView from an ArrayList defined in the Application class. However, I end up with a NullPointerException whenever I scroll with no cause given the in the Logcat.

LogCat output:

05-17 11:05:35.365: W/System.err(2173): java.lang.NullPointerException
05-17 11:05:35.375: W/System.err(2173):     at in.net.maloo.HomeScreenListView$myAdapter.getView(HomeScreenListView.java:66)
05-17 11:05:35.385: W/System.err(2173):     at android.widget.AbsListView.obtainView(AbsListView.java:1294)
05-17 11:05:35.385: W/System.err(2173):     at android.widget.ListView.makeAndAddView(ListView.java:1727)
05-17 11:05:35.395: W/System.err(2173):     at android.widget.ListView.fillDown(ListView.java:652)
05-17 11:05:35.395: W/System.err(2173):     at android.widget.ListView.fillGap(ListView.java:623)
05-17 11:05:35.395: W/System.err(2173):     at android.widget.AbsListView.trackMotionScroll(AbsListView.java:2944)
05-17 11:05:35.405: W/System.err(2173):     at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:2485)
05-17 11:05:35.405: W/System.err(2173):     at android.os.Handler.handleCallback(Handler.java:587)
05-17 11:05:35.405: W/System.err(2173):     at android.os.Handler.dispatchMessage(Handler.java:92)
05-17 11:05:35.415: W/System.err(2173):     at android.os.Looper.loop(Looper.java:123)
05-17 11:05:35.415: W/System.err(2173):     at android.app.ActivityThread.main(ActivityThread.java:4627)
05-17 11:05:35.415: W/System.err(2173):     at java.lang.reflect.Method.invokeNative(Native Method)
05-17 11:05:35.425: W/System.err(2173):     at java.lang.reflect.Method.invoke(Method.java:521)
05-17 11:05:35.425: W/System.err(2173):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-17 11:05:35.425: W/System.err(2173):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-17 11:05:35.425: W/System.err(2173):     at dalvik.system.NativeStart.main(Native Method)

Code:

package in.net.maloo;

import android.app.ListActivity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class HomeScreenListView extends ListActivity {

    private static class myAdapter extends BaseAdapter{
        private LayoutInflater mInflater;

        public myAdapter(Context context){
            mInflater = LayoutInflater.from(context);

        }

        public int getCount() {
            // TODO Auto-generated method stub
            return myApp.feedLength(0);
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(int position, View conertView, ViewGroup parent) {
            ViewHolder holder;

            if (conertView == null) {
                conertView = mInflater.inflate(R.layout.listview_homescreen, null);
                holder = new ViewHolder();

                holder.text1 = (TextView) conertView.findViewById(R.id.hs_listview_symbol);
                holder.text2 = (TextView) conertView.findViewById(R.id.hs_listview_price);
                holder.text3 = (TextView) conertView.findViewById(R.id.hs_listview_unit);
                holder.text4 = (TextView) conertView.findViewById(R.id.hs_listview_change);
                holder.text5 = (TextView) conertView.findViewById(R.id.hs_listview_pcp);
            } else {

                holder = (ViewHolder) conertView.getTag();
            }

            String com, ltp, volume, ltq, pcp;
            com = myApp.getFuturesData(position, "Commodity", 0) + " - " + myApp.getFuturesData(position, "Expiry", 0);
            ltp = myApp.getFuturesData(position, "LTP") + "";
            ltq = "LTQ: " + myApp.getFuturesData(position, "LTQ");
            volume = "Volume: " + myApp.getFuturesData(position, "Volume");
            pcp = "PCP: " + myApp.getFuturesData(position, "PCP");

            try {

            holder.text1.setText(com);
            Log.e("Position", com);
            holder.text2.setText(ltp);
            holder.text3.setText(volume);
            holder.text4.setText(ltq);
            holder.text5.setText(pcp);
            return conertView;
            }
            catch (NullPointerException e){
                e.printStackTrace();
            }
            finally {
                return conertView;
            }
        }

        static class ViewHolder {
            TextView text1;
            TextView text2;
            TextView text3;
            TextView text4;
            TextView text5;
        }
    }

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setListAdapter(new myAdapter(this));        

}
}

listview_homescreen layout:

<?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" >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="75dip" >

        <TextView
            android:id="@+id/hs_listview_symbol"
            android:layout_width="200dip"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_alignParentTop="true"
            android:layout_alignRight="@+id/hs_listview_change"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@android:color/tertiary_text_light"
            android:textSize="17dip" />

        <TextView
            android:id="@+id/hs_listview_price"
            android:layout_width="75dip"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentTop="true"
            android:text="28,788"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textSize="15dip" />

        <TextView
            android:id="@+id/hs_listview_unit"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:text="Vol"
            android:textAppearance="?android:attr/textAppearanceSmall" />

        <TextView
            android:id="@+id/hs_listview_pcp"
            android:layout_width="75dip"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:text="PCP"
            android:textAppearance="?android:attr/textAppearanceSmall" />

        <TextView
            android:id="@+id/hs_listview_change"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:text="Small Text"
            android:textAppearance="?android:attr/textAppearanceSmall" />
    </RelativeLayout>

</LinearLayout>

Apparently, convertView.getTag() method is returning null for some reason, and hence all the problem. The same code was working fine when I was earlier using direct reference to an Array defined in myApp but then I switched to using ArrayList of a custom class holding different data types.

If it matters, the ListView activity is contained inside a Tabhost containing 3 tabs.

Any help with this will be much appreciated. Thanks!

  • 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-04T00:51:28+00:00Added an answer on June 4, 2026 at 12:51 am
    if (conertView == null) {
       conertView = mInflater.inflate(R.layout.listview_homescreen, null);
       holder = new ViewHolder();
    
       holder.text1 = (TextView) conertView.findViewById(R.id.hs_listview_symbol);
       holder.text2 = (TextView) conertView.findViewById(R.id.hs_listview_price);
       holder.text3 = (TextView) conertView.findViewById(R.id.hs_listview_unit);
       holder.text4 = (TextView) conertView.findViewById(R.id.hs_listview_change);
       holder.text5 = (TextView) conertView.findViewById(R.id.hs_listview_pcp);
       **conertView.setTag(holder);**
    } else {
      holder = (ViewHolder) conertView.getTag();
    }
    

    you were missing conertView.setTag(holder);

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

Sidebar

Related Questions

I'm trying to display information from my ObservableCollection<MyData> in a ListView . MyData has:
I am trying to retrieve data from mysql then display it on android listview.
I'm trying to display items from a database into a listview for all dates
I'm trying to display information from a Cursor in a ListView , each row
I am trying to display video files in listview from folder created in sdcard.
I'm trying to display data from a non-Sugar table in a custom listview in
I am trying to display ListView . I have created one activity , in
I am trying to display only selected items in list view. public class Mact
Ive been trying to display formatted content blocks from a xml file with no
I'm trying to display an svg graph with associated javascript in my application using

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.