Reputation: 51
When I try passing a boolean parameter which is declared locally in another method the compiler delivers the the error:
Error:(40, 71) java: cannot find symbol symbol: variable frei
location: class flugVerein
the method that gets the boolean variable passed:
public static void verfügbar(int[] flugAnzahl, String[] vorname, String[] bezeichnung, int[] zeit, boolean frei)
where the variable is declared:
public static void ganzeTag(int[] zeit, String[] vorname, String[] nachname, String[] bezeichnung) {
Scanner sc = new Scanner(System.in);
System.out.println("Geben Sie die Bezeichnung des Fluges ein: ");
String eingabe = sc.nextLine();
boolean frei = false;
the method call in the main method:
verfügbar(flugAnzahl, vorname, bezeichnung, zeit, frei);
Upvotes: 0
Views: 898
Reputation: 1265
You can't access the frei
variable since you are in a different method. It was declared in the ganzeTag
method, but you are trying to access it in the main
method. There are a few things you can do. The easiest way in my opinion is to make it a field.
private static boolean frei;
Then in the ganzeTag
method:
public static void ganzeTag(int[] zeit, String[] vorname, String[] nachname, String[] bezeichnung) {
Scanner sc = new Scanner(System.in);
System.out.println("Geben Sie die Bezeichnung des Fluges ein: ");
String eingabe = sc.nextLine();
frei = false; // don't put the boolean.
Actually, you don't even need that line, because the default value for the boolean field is false.
public static void ganzeTag(int[] zeit, String[] vorname, String[] nachname, String[] bezeichnung) {
Scanner sc = new Scanner(System.in);
System.out.println("Geben Sie die Bezeichnung des Fluges ein: ");
String eingabe = sc.nextLine();
Upvotes: 1