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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T05:08:43+00:00 2026-06-12T05:08:43+00:00

I looked here to try and solve my problem. It is similar but I

  • 0

I looked here to try and solve my problem. It is similar but I use fragments so when I need context I usually need to call getActivity().

Basically I have App.java as described in the link above, I have

android:name=".App" inside my <application> tag

added to my AndroidManifest.xml. Now I have this class I use to collect all the things i use frequently:

public class MiscMethods{
public static void ErrorToast(int errorCode) {
    String errorString = null;
    if(errorCode==1){ errorString = App.getContext().getString(R.string.error_tooManyFieldsEmpty);}
    if(errorCode==2){ errorString = App.getContext().getString(R.string.error_featureComingSoon);}
    if(errorCode==3){ errorString = App.getContext().getString(R.string.error_SwitchBreak);}
    else{errorString="Wrong Error Code";}
    Toast errormsg = Toast.makeText(App.getContext(), errorString, Toast.LENGTH_SHORT);
    errormsg.setGravity(Gravity.CENTER, 0, 0);
    errormsg.show();
}
}

In one of my fragments I call

MiscMethods.ErrorToast(1);

I just get the “Wrong Error Code” message from the “else {}” part of my method

Can you help me make this right?

  • 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-12T05:08:44+00:00Added an answer on June 12, 2026 at 5:08 am

    better formatting would have made your issue easier to find:

    public static void ErrorToast(int errorCode) {
        String errorString = null;
        if (errorCode == 1) {
            errorString = App.getContext().getString(R.string.error_tooManyFieldsEmpty);
        }
        if (errorCode == 2) {
            errorString = App.getContext().getString(R.string.error_featureComingSoon);
        }
        if (errorCode == 3) {
            errorString = App.getContext().getString(R.string.error_SwitchBreak);
        } else {
            errorString = "Wrong Error Code";
        }
        Toast errormsg = Toast.makeText(App.getContext(), errorString, Toast.LENGTH_SHORT);
        errormsg.setGravity(Gravity.CENTER, 0, 0);
        errormsg.show();
    }
    

    As you might now see is that your if (errorCode == 1) should work but will be overridden as if (errorCode == 3) will be false in this case and your else will override your errorString variable.

    A switch(errorCode) and the 3 cases are what you are looking for.

    Final tip: improve your formatting!

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

Sidebar

Related Questions

I've looked around here for similar question but couldn't find any that solved my
I've looked at several questions here that looked similar, but none of them discussed
I've looked at similar questions here but I haven't found one particular to my
I've looked at a few other try catch finally questions on here but I'm
I have looked around here and the Internet in general but it seems this
I have looked on here and tried every answer available, but it is still
I've looked at other examples here, but they seem to be replacing the contents
I'm unable to delete my file, i have looked here but can't find the
I have looked on here and found a few examples but nothing works so
OK, this is impossible, but I will try to explain the situation here. Let's

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.