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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:37:01+00:00 2026-06-07T01:37:01+00:00

I have developed one application which has 15 screens. Now I want to display

  • 0

I have developed one application which has 15 screens. Now I want to display custom toast message in all those 15 screens. To do so, I have inflated one layout. But it’s working only on one screen. So, I wrote a single method to display custom Toast on all screens. Whenever I want to display toast message, I would just call that method. But i got java.lang.NullPointerException. How to resolve this? The following is my code,

public static void showToastMessage(String message){

               LayoutInflater inflater = ((Activity) context).getLayoutInflater();

                View layout = inflater.inflate(R.layout.custom_toast,
                  (ViewGroup) ((Activity) context).findViewById(R.id.customToast));
            // set a message
                TextView text = (TextView) layout.findViewById(R.id.text);
                text.setText(message);

                // Toast...
                Toast toast = new Toast(context);
                toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
                toast.setDuration(Toast.LENGTH_LONG);
                toast.setView(layout);
                toast.show();
           }

Log is

java.lang.NullPointerException

    at com.guayama.utilities.CommonMethods.showToastMessage(CommonMethods.java:474)

    at android.view.View.performClick(View.java:3511)

    at android.view.View$PerformClick.run(View.java:14105)

    at android.os.Handler.handleCallback(Handler.java:605)

    at android.os.Handler.dispatchMessage(Handler.java:92)

    at android.os.Looper.loop(Looper.java:137)

    at android.app.ActivityThread.main(ActivityThread.java:4424)

    at java.lang.reflect.Method.invokeNative(Native Method)
  • 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-07T01:37:05+00:00Added an answer on June 7, 2026 at 1:37 am

    change your method

    from

    showToastMessage(String message)
    

    to

    showToastMessage(Context context,String message);
    

    it seems context problem to me

    your function will look like this

    public static void showToastMessage(Context context,String message){
    
                   LayoutInflater inflater = context.getLayoutInflater();
    
                    View layout = inflater.inflate(R.layout.custom_toast,
                      (ViewGroup) ((Activity) context).findViewById(R.id.customToast));
                // set a message
                    TextView text = (TextView) layout.findViewById(R.id.text);
                    text.setText(message);
    
                    // Toast...
                    Toast toast = new Toast(context);
                    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
                    toast.setDuration(Toast.LENGTH_LONG);
                    toast.setView(layout);
                    toast.show();
               }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application which has many services and one UI module. All these
I have developed one application in which i have to detect whether user has
I have developed a Windows application which has one DataGrid. I am assigning Defaultview
We have a web application which has been developed over the past 7 months.
We have developed a messaging application in j2me which adds text message, gets pictures
I have developed one application which will have activities and one background service and
I have developed one application which is running properly in android 4.0(icecream Sandwhich) but
I have developed one windows application,which is checking for newly updated or generated file
I have developed an application with mac and for one month now, Im trying
I have developed one window application which requires one report to be print. This

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.