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

if you have an android app that has more than one Activity, and Activity
I have an error in onCreateDialog() NullPointerException in this code: import android.app.Activity; import android.app.Dialog;
I have a class that extends android.app.Dialog, the layout is done in an xml
I have an android-app with a listview in an activity. The listview has, if
I have got this logcat error more then one time. This time I started
I have a fledgling app under development, which I am installing to my Android
I have an app that's built for Android 2.2, so I'm not using the
We have an Android app and a Web Service. We want to download part
I have an Android app with a ListActivity in the main view. The list
I have created a small and simple android app. I tried installing it on

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.