-3

I have the below code:

public class class1 {
.............

public static void calls(String[] args) {

    ................

Now I am trying to call this method "calls" of "class1" in an another class within an another method like below code:

public class newClass extends abc {

public void executemywork() throws CIException {

class1.calls(args); //error here "args" cannot be resolved to a variable

I have tried looking at other solutions in stack overflow. I even tried by creating object of "class1" and using it in the second method. I am still getting the same error here. The error says "args" cannot be resolved to a variable. Both The classes are in different packages and I have imported the other class as well.

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
jane
  • 211
  • 9
  • 30
  • The call is fine. The problem is, as the error message says, you haven't defined `args`, which is something you're passing **into** `calls`. – T.J. Crowder Nov 10 '17 at 14:06
  • You didn't declare your variable args in the newClass class – losusovic Nov 10 '17 at 14:07
  • The error has nothing to do with the location of the method. You simply do not have anything named `args`. –  Nov 10 '17 at 14:07
  • This is a duplicate, possibly of https://stackoverflow.com/questions/7588784/java-variable-name-cannot-be-resolved-to-a-variable, but I'm still looking... – T.J. Crowder Nov 10 '17 at 14:07
  • Si if i initialize as String[] args = null; this should do the job – jane Nov 10 '17 at 14:10
  • Extra: Java Convention remark. Class names start with Capital letters and static method calls should be called on the class. – Jack Flamp Nov 10 '17 at 14:16

2 Answers2

3

Declare and give a value to args like

String[] args = new String[]{"a","b","c"};
0

Its a compilation error You are doing class1.calls(args); but here args is not defined. Hence the compilation error.

Change your code something like

public class newClass extends abc {

            public void executemywork() throws CIException {
                    String[] args = new String[]{"a","b","c"};
                    class1.calls(args); //error here "args" cannot be resolved to a variable
            }
}