Making two classes work together in Java

666 Views Asked by At

I am trying to compile my NameRecord.java file, but I keep getting the following error: cannot find symbol num = input.nextLine(); It's saying the Scanner input is the issue, but I initialized and populate the Scanner input before I call the NameRecord class.

Both of these classes are in the same directory, so I am not sure what I am doing wrong.

This is the class that calls the NameRecord class. It does not compile I keep getting a symbol not found Method NameRecord(String):

I left out a couple of methods that are also included in this class to conserve space.

1

There are 1 best solutions below

2
On

The issue that is preventing this from compiling is that the NameRecord class has no way of knowing about input. This is an issue of scope. The only place where your code "knows about" input is within the try-catch block in the main method of NameGameFrame. You should pass the String returned by input.nextLine() to NameRecord for this to work the way you want it to.

That being said, this is one of about 20 problems with your code.