Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 203
  • Last Modified:

can this be made static

public Vector getConvertedError( String errCode) throws PropertyApplicationException
      {
            Vector v1 = new Vector();
            if( errCode.compareTo(props.getValue(ServicesConstants.ACCOUNT_NON_TELCO_ERROR_CODE)) == 0)
            {
                  v1.add(props.getValue(ServicesConstants.ACCOUNT_NON_TELCO_ERROR_CODE));
                  v1.add(props.getValue(ServicesConstants.ACCOUNT_NON_TELCO_ERROR_MSG));
            }
            else if ( errCode.compareTo(props.getValue(ServicesConstants.ACCOUNT_INVALID_COS_ERROR_CODE)) == 0)
            {
                  v1.add(props.getValue(ServicesConstants.ACCOUNT_INVALID_COS_ERROR_CODE));
                  v1.add(props.getValue(ServicesConstants.ACCOUNT_INVALID_COS_ERROR_MSG));
            }      
            else if ( errCode.compareTo(props.getValue(ServicesConstants.ACCOUNT_SIWTN_ERROR_CODE)) == 0)
            {
                  v1.add(props.getValue(ServicesConstants.ACCOUNT_SIWTN_ERROR_CODE));
                  v1.add(props.getValue(ServicesConstants.ACCOUNT_SIWTN_ERROR_MSG));
            }
            else if ( errCode.compareTo(props.getValue(ServicesConstants.ACCOUNT_UNE1_ERROR_CODE)) == 0)
            {
                  v1.add(props.getValue(ServicesConstants.ACCOUNT_UNE1_ERROR_CODE));
                  v1.add(props.getValue(ServicesConstants.ACCOUNT_UNE1_ERROR_MSG));
            }
            else if( errCode.compareTo(props.getValue(ServicesConstants.ACCOUNT_UNN1_ERROR_CODE)) == 0)
            {
                  v1.add(props.getValue(ServicesConstants.ACCOUNT_UNN1_ERROR_CODE));
                  v1.add(props.getValue(ServicesConstants.ACCOUNT_UNN1_ERROR_MSG));
            }
            else if( errCode.compareTo(props.getValue(ServicesConstants.CSR_NO_DATA_FOUND)) == 0)
            {
                   v1.add(props.getValue(ServicesConstants.CSR_NO_DATA_FOUND));
                   v1.add(props.getValue(ServicesConstants.CSR_NO_DATA_FOUND));
            }
            else if (errCode.compareTo(props.getValue(ServicesConstants.IM_ACCOUNT_TO_LARGE_ERROR_CODE)) == 0)
            {
                  v1.add(props.getValue(ServicesConstants.IM_ACCOUNT_TO_LARGE_ERROR_CODE));
                  v1.add(props.getValue(ServicesConstants.IM_ACCOUNT_TO_LARGE_ERROR_MSG));
            }
            else if (errCode.startsWith(props.getValue(ServicesConstants.IM_SYSTEM_UNAVAIL_ERROR_CODE)) )
            {
                  v1.add(props.getValue(ServicesConstants.IM_SYSTEM_UNAVAIL_ERROR_CODE));
                  v1.add(props.getValue(ServicesConstants.IM_SYSTEM_UNAVAIL_ERROR_MSG));
            }
            else if (errCode.startsWith(props.getValue(ServicesConstants.IM_INVALID_INPUT_COMB_ERROR_CODE)))
            {
                  v1.add(props.getValue(ServicesConstants.IM_INVALID_INPUT_COMB_ERROR_CODE));
                  v1.add(props.getValue(ServicesConstants.IM_INVALID_INPUT_COMB_ERROR_MSG));
            }
            else if (errCode.startsWith(props.getValue(ServicesConstants.IM_SYSTEM_TIMEOUT_ERROR_CODE)))
            {
                  v1.add(props.getValue(ServicesConstants.IM_SYSTEM_TIMEOUT_ERROR_CODE));
                  v1.add(props.getValue(ServicesConstants.IM_SYSTEM_TIMEOUT_ERROR_MSG));
            }
            else if(errCode.startsWith(props.getValue(ServicesConstants.ACCOUNT_TIMEOUT_ERROR_CODE)))
            {
                  v1.add(props.getValue(ServicesConstants.ACCOUNT_TIMEOUT_ERROR_CODE));
                  v1.add(props.getValue(ServicesConstants.ACCOUNT_TIMEOUT_ERROR_MSG));
            }
            else if( errCode.startsWith(props.getValue(ServicesConstants.IM_SCHEDULED_DOWNTIME_ERROR_CODE).trim()) )
            {
                  v1.add( props.getValue(ServicesConstants.IM_SCHEDULED_DOWNTIME_ERROR_CODE));
                  v1.add( props.getValue(ServicesConstants.IM_SCHEDULED_DOWNTIME_ERROR_MSG));
            }
            else
            {
                  v1.add(props.getValue(ServicesConstants.ACCOUNT_INVALID_ERROR_CODE));
                  v1.add(props.getValue(ServicesConstants.ACCOUNT_INVALID_ERROR_MSG));      
            }
            return v1;
      }

I guess I am confused what method to make static ? it beats me when a method can be static ? Here the input errorId can be different , but the properties file can be constant
0
skn73
Asked:
skn73
  • 2
2 Solutions
 
bobbit31Commented:
a static method is one that can be called w/o creating an instance of the class...

e.g.

public class StaticClass {
  public static int blah (String s) {
    return s + "... Blah";
  }
}

in the above case... you can just do something like (in your main class):

System.out.println(StaticClass.blah("hello world"));

if you were to remove the static from the method declaration, you would have to do:

StaticClass sc = new StaticClass();
System.out.println(sc.blah("hello world"));

that being said, what is the error you are getting?
how are you calling your method?
0
 
bobbit31Commented:
public static String blah (String s) {
...
}
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
(It has been a long time since I have done any Java)

When a method is static, everything it accesses must also be static, so your props variable must be declared static as well.

~IM
0
 
DrWarezzCommented:
>"I guess I am confused what method to make static ?"
Make this method static:

public Vector getConvertedError( String errCode);

However, as Idle_Mind correctly pointed out (unless we're both terribly mistaken), whatever you use to access it must also be static.
For example,

public static void main ( String [] args ) {
  // ... Some code ...
  Vector v_errors = getConvertedError( s_errCode );
}

(this is all assuming that the "getConvertedError()" method, is in the same class as that calling it)..

However, if you call it from a method that is NOT static, you need to create a class object, like so:

public void methodName () {
  // ... Some code ...
  ClassName o_cn = new ClassName ();  // Add any arguments to the constructor if necessary.
  Vector c_errors = o_cn.getCnvertedErrors( s_errCode );
}

I hope that helps! :-)
[r.D]
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now