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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:50:40+00:00 2026-06-07T22:50:40+00:00

I know, this is again a repeated question but my case it is different

  • 0

I know, this is again a repeated question but my case it is different question.

I have a class abc with a static function & a Handler. Earlier i couldn’t able call handler from a static function. Then i googled for Access a non-static function from a static function & found an solution is to create an instance of class & access non-static variable. But now, why, i m getting this error.

E/AndroidRuntime(13343): java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare()

public class abc
 {    
    static public void Instantiate()
    {
         abc xyz = new abc();
         xyz.handler.sendEmptyMessage(1);      **//GETTING ERROR IN THIS LINE**
    }

    public Handler handler = new Handler() 
        {
                public void handleMessage(Message msg) 
                {
                        switch (msg.what)
                        {
                        }
                 }
        }

}

My Question: How can i send message to handler from a static function?

Thankx.

  • 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-07T22:50:42+00:00Added an answer on June 7, 2026 at 10:50 pm

    check the place where you are doing this:

    abc.Instantiate();
    

    and replace it with

    runOnUiThread(new Runnable() {
    
        @Override
        public void run() {
            abc.Instantiate();
        }
    });
    

    I hope you’re calling it from an Activity

    Some Explanation (quoting bicska88) 🙂


    What causes the problem, doesn’t have anything to do with the fact that you send a message to a Handler object from within a static function. The problem is that you send a message to the handler from a thread that has not called Looper.prepare() (as the error message says, the thread doesn’t have a message loop). This may be fixed by explicitly calling Looper.prepare() before-while, or by running the code on the UIThread.


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

Sidebar

Related Questions

I know this is repeated question on Stack. But in my case the URL
I know this is an old question, but I have spend any hours on
I apologize because I know this has been covered over and over again, but
i know this is a stupid question but i d'ont know how to do
Ok guys, So I know this has been covered before, but what my question
I know this has been discussed over and over again but I can't find
I know this has been asked before. But I have exhausted the options given
I have asked this question earlier today but I didn't provide enough information and
I know this question has been asked multiple times but all the answers seem
I know this topic has been discussed and killed over and over again, but

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.