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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:50:43+00:00 2026-05-23T09:50:43+00:00

In my android app, I have one Activity and more java class which is

  • 0

In my android app, I have one Activity and more java class which is not an activity.
So there is a get method in this other java class, which returns an Object. This method starts a new thread to gets the data and attaches it with the object

Now I am calling this get method in my Activity to get that object. I am doing something like this –

mNewsList = new ArrayList<NewsContentManager.NewsPojo>();
mNewsList = manager.getNewsList();

and the method is this -

    public ArrayList<NewsPojo> getNewsList() {
        Log.v("TAG", ""+newsList);
        if(newsList == null)
        {
            Thread t = new Thread(){
                public void run(){

                    Log.v("TAG", "Inside run");

                    np1 = new NewsPojo();
                    np1.setTitle("A");
                    np1.setDescription("dhghfdklsa");


                    np2 = new NewsPojo();
                    np2.setTitle("B");
                    np2.setDescription("dhghfdklsa");


                    np3 = new NewsPojo();
                    np3.setTitle("c");
                    np3.setDescription("dhghfdklsa");

                    newsList = new ArrayList<NewsPojo>();

                    Log.v("in run",""+newsList);

                    newsList.add(np1);
                    newsList.add(np2);
                    newsList.add(np3);

                    Log.v("in run",""+newsList.size());

                    setNewsList(newsList);

                    handler.sendEmptyMessage(0);

                }// end of run
            };// end of thread
            t.start();
        }//end of if

        return newsList;
    }

But I am getting nullPointer Exception in my Activity.
If I remove Thread from this method then it works correctly.
What should I do ?

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-05-23T09:50:43+00:00Added an answer on May 23, 2026 at 9:50 am

    Additionally to my comment to your question.

    First, try to avoid using Threads in such a way. Use AsyncTask instead.
    On it’s preExecute show some dialog to the user, that you are loading a list, on it’s doInBackground put your logic that will return new list, and in postExecute just dismiss the dialog and proceed.

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

Sidebar

Related Questions

In my Android app, I have a tabbed Activity . In one of the
I have an android-app with a listview in an activity. The listview has, if
I have two threads in an Android application, one is the view thread, and
Is this possible in an Android app? I want to make it so that
in my android app i have an ui-update-thread that keeps all my views up-to-date.
I have an application which has 11 different activities. One of these activities is
I'm building an Android app and I want to copy the text value of
I'm building a mobile web app targeting Android users. I need to know what
I'm doing some Android development, and I much prefer Visual Studio, but I'll have
Has anyone managed to use ItemizedOverlays in Android Beta 0.9? I can't get it

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.