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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:25:42+00:00 2026-06-15T23:25:42+00:00

I am using a list view with a custom adapter.I am getting a null

  • 0

I am using a list view with a custom adapter.I am getting a null pointer exception whose reason is unknown.I have even tried to debug it but the debugger is not able to locate the location of the exception.This is the code:

if(SplashActivity.s_contactNameArrayListSplash != null && SplashActivity.s_contactNameArrayListSplash.size() != 0)
        {
            if(m_contactAdapterSetTheRule  == null)
            {
                m_contactAdapterSetTheRule = new ContactAdapterSetRule(ShowTheContacts1.this, R.layout.showthecontacts, SplashActivity.s_contactNameArrayListSplash);

                //add the footer before adding the adapter, else the footer will not load!
                //  View footerView = ((LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.listfooter, null, false);
                View footerView  = getLayoutInflater().inflate(R.layout.listfooter, null);
                m_lvShowContactsSetTheRule.addFooterView(footerView);

                m_lvShowContactsSetTheRule.setAdapter(m_contactAdapterUpdatingRule);
            }


            m_lvShowContactsSetTheRule.setOnScrollListener(new OnScrollListener(){

                //useless here, skip!
                @Override
                public void onScrollStateChanged(AbsListView view, int scrollState) {}

                @Override
                public void onScroll(AbsListView view, int firstVisibleItem,
                        int visibleItemCount, int totalItemCount) {


                    //what is the bottom item that is visible
                    int lastInScreen = firstVisibleItem + visibleItemCount;             

                    //is the bottom item visible & not loading more already ? Load more !
                    if((lastInScreen == totalItemCount) && !(m_loadingMore)){                   
                        Thread thread =  new Thread(null, loadMoreListItems);
                        thread.start();
                    }
                }
            });


            //Load the first 25 items
            Thread thread =  new Thread(null, loadMoreListItems);
            thread.start();

        }
        else
        {
            Log.e("Info: ","No any contact present in the add Rule Array list");
            Toast.makeText(ShowTheContacts1.this,"No Contact is present in the contact list",Toast.LENGTH_LONG).show();
            Intent intent = new Intent(ShowTheContacts1.this,Settings.class);
            startActivity(intent);
        }       
    }
    catch(Exception e)
    {
        Log.e("Exception: ",e+" in setTheRuleContactListMaker() of ShowTheContacts1.java");
    }
}

//Runnable to load the items 
Runnable loadMoreListItems = new Runnable() {           
    @Override
    public void run() {
        //Set flag so we cant load new items 2 at the same time
        m_loadingMore = true;

        //Reset the array that holds the new items
        m_myListItems = new ArrayList<String>();

        if(SplashActivity.s_contactNameArrayListSplash.size() < m_itemsPerPage)
            m_itemsPerPage = SplashActivity.s_contactNameArrayListSplash.size();

        //Get 15 new listitems
        for (int i = 0; i < m_itemsPerPage; i++) {      

            //Fill the item with some bogus information
            m_myListItems.add(SplashActivity.s_contactNameArrayListSplash.get(i).toString());                           
        }

        //Done! now continue on the UI thread
        runOnUiThread(returnRes);

    }
};  


//Since we cant update our UI from a thread this Runnable takes care of that! 
Runnable returnRes = new Runnable() 
{
    @Override
    public void run() 
    {
        //Loop thru the new items and add them to the adapter
        if(m_myListItems != null && m_myListItems.size() > 0)
        {
            for(int i=0;i < m_myListItems.size();i++)
            {
                m_contactAdapterSetTheRule.add(m_myListItems.get(i));   
            }
        }

        //Tell to the adapter that changes have been made, this will cause the list to refresh
        m_contactAdapterSetTheRule.notifyDataSetChanged();

        //Done loading more.
        m_loadingMore = false;

    }
};

This is the error log:

12-11 15:12:28.535: E/AndroidRuntime(794): Uncaught handler: thread main exiting due to uncaught exception
12-11 15:12:28.545: E/AndroidRuntime(794): java.lang.NullPointerException
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.widget.ListView.setupChild(ListView.java:1693)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.widget.ListView.makeAndAddView(ListView.java:1671)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.widget.ListView.fillDown(ListView.java:637)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.widget.ListView.fillFromTop(ListView.java:694)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.widget.ListView.layoutChildren(ListView.java:1521)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.widget.AbsListView.onLayout(AbsListView.java:1113)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.view.View.layout(View.java:6830)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:998)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.widget.LinearLayout.onLayout(LinearLayout.java:918)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.view.View.layout(View.java:6830)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.view.View.layout(View.java:6830)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1119)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:998)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.widget.LinearLayout.onLayout(LinearLayout.java:918)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.view.View.layout(View.java:6830)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.widget.FrameLayout.onLayout(FrameLayout.java:333)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.view.View.layout(View.java:6830)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.view.ViewRoot.performTraversals(ViewRoot.java:996)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.view.ViewRoot.handleMessage(ViewRoot.java:1633)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.os.Handler.dispatchMessage(Handler.java:99)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.os.Looper.loop(Looper.java:123)
12-11 15:12:28.545: E/AndroidRuntime(794):  at android.app.ActivityThread.main(ActivityThread.java:4363)
12-11 15:12:28.545: E/AndroidRuntime(794):  at java.lang.reflect.Method.invokeNative(Native Method)
12-11 15:12:28.545: E/AndroidRuntime(794):  at java.lang.reflect.Method.invoke(Method.java:521)
12-11 15:12:28.545: E/AndroidRuntime(794):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
12-11 15:12:28.545: E/AndroidRuntime(794):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

After these 2 lines,the debugger is moving to exception itself.

Thread thread =  new Thread(null, loadMoreListItems);
        thread.start();

I have searched a lot to get the work around,but am not getting any clue.Please help me.Thanks in advance.

  • 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-15T23:25:43+00:00Added an answer on June 15, 2026 at 11:25 pm

    Try using:

    Thread thread =  new Thread(new Runnable() {
    
            @Override
            public void run() {
                //Set flag so we cant load new items 2 at the same time
        m_loadingMore = true;
    
        //Reset the array that holds the new items
        m_myListItems = new ArrayList<String>();
    
        if(SplashActivity.s_contactNameArrayListSplash.size() < m_itemsPerPage)
            m_itemsPerPage = SplashActivity.s_contactNameArrayListSplash.size();
    
        //Get 15 new listitems
        for (int i = 0; i < m_itemsPerPage; i++) {      
    
            //Fill the item with some bogus information
            m_myListItems.add(SplashActivity.s_contactNameArrayListSplash.get(i).toString());                           
        }
    
        //Done! now continue on the UI thread
        runOnUiThread(returnRes);
            }
        } );
            thread.start();
    

    instead of:

    Thread thread =  new Thread(null, loadMoreListItems);
            thread.start();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have created custom listview by using the Base adapter. List view contains Text
I have created a custom listview using adapter. Each row of the list view
I am getting XML data from url and displaying using a custom list adapter
I have used a custom array adapter to populate my list view.The problem i
I have List of items. I'm using custom adapter (Android 1.5). Everything works perfectly,
I need a little help with my custom list view adapter. I'm using the
I have created a custom Base Adapter class, to populate a list view with
Right now I am using a custom list view and I am inflating an
I am using a list view and an adapter for loading a list,each list
I have created a custom listview using SimpleAdapter and in each row of list

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.