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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:29:55+00:00 2026-06-06T06:29:55+00:00

I am having trouble with passing some variables through a method and then having

  • 0

I am having trouble with passing some variables through a method and then having that method return a value. The checkValue method is supposed to look at each of the array items in the orderSplit array and if there is an error with them, return an error message, if not it will return an empty errorMessage. But as of right now the program doesn’t seem to be executing the method at all. Any suggestions?

Here is an example of my code:

public class Foo {
    public static void main(String args[]) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String order = null;
        try {
            order = br.readLine();
        } catch (IOException exc) {
            System.out.println("ERROR: A Problem has occured");
        }

        String[] orderSplit = null;
        orderSplit = order.split(" ");

        String errorMessage = "";
            checkValue(orderSplit, errorMessage);
        if (errorMessage == "") {
            System.out.println("SUCCESS");
        }

    }
    public static String checkValue(String[] orderSplit, String errorMessage) {
             // check the ordersplit values
             return errorMessage;
    }
}
  • 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-06T06:29:57+00:00Added an answer on June 6, 2026 at 6:29 am

    You don’t assign the result of the method to anything. Change your code to:

    String errorMessage = checkValue(orderSplit);
    

    And not that the checkValue method doesn’t need any error message as argument. It will create one by itself and return it to the caller.

    Also, assigning null to a variable you reassign immediately after, like this:

    String[] orderSplit = null;
    orderSplit = order.split(" ");
    

    is unnecessary. You just need

    String[] orderSplit = order.split(" ");
    

    And you should never compare Strings with ==. == tests if two variables reference the same String object. You should use the equals() method, which tests if two Strings contain the exact same sequence of characters:

    if (errorMessage.equals("")) {
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some trouble passing a number as an argument for a method: -
Hello i am having trouble with passing a php return value to the innerHTML
Hi i am having some trouble passing variables/doing functions from other classes, Right now
I'm having some trouble passing in dynamic variables into my query. Please ignore the
I'm having some trouble parsing a JSON that I obtain from my DB to
CakePHP Newbie :) I am having trouble accessing another controller and passing that data
having some trouble passing a function as a parameter of another function... ERROR: Error
I'm having trouble figuring out how to display some return JSON objects. My script
Having some trouble passing values from one class to another. I basically have a
I'm having some trouble writing a query using variables. Here's my code Dim bondnumber

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.