Я пытаюсь создать метод. Основываясь на том, что я прочитал и наблюдал за мной, хотя это был способ создать, а затем вызвать метод, но я не уверен, правильно ли я это делаю. Я получил и ошибки, когда я выполнил это. Если у вас есть предложения по улучшению кода, который будет очень цениться.Ошибка при попытке вызова метода
Здесь ошибка:
Error: can not find symbol.
И это дало мне около 10 из этих ошибок всех Referance массивов в общественных статических недействительных getLabelData(), где я пытался создать метод.
Вот код:
import javax.swing.JOptionPane;
public class MailOrderCall
{
public static void main(String[] args)
{
streetAddress, city, state, zip.
String nameAddressArray[] = new String[7];
String numBoxesInput;
int numBoxes;
String enterAnother = "Y";
int counter;
getLabelData();
while(enterAnother.equalsIgnoreCase("Y"))
{
counter = 1;
// begin the inner loop to display a label and increment the counter
while(counter <= numBoxes)
{
System.out.println(nameAddressArray[0] + " " + nameAddressArray[1] + " " + nameAddressArray[2]);
System.out.println(nameAddressArray[3]);
System.out.println(nameAddressArray[4] + ", " + nameAddressArray[5] + " " + nameAddressArray[6]);
System.out.println("Box " + counter + " of " + numBoxes);
System.out.println();
counter = counter + 1;
} // end while
// ask the user if finished entering mail orders
enterAnother = " "; // initialize the variable to something other than "Y" before sending the prompt
enterAnother = JOptionPane.showInputDialog("Do you want to produce more labels? Y or N");
// validate input for enterAnother... keep them here until they enter Y, y, N, or n
while (!enterAnother.equalsIgnoreCase("Y") && !enterAnother.equalsIgnoreCase("N"))
{
enterAnother = JOptionPane.showInputDialog(null, "Invalid Response. Please enter Y or N.",
"DATA ENTRY ERROR", JOptionPane.ERROR_MESSAGE);
} // end while
if(enterAnother.equalsIgnoreCase("Y"))
{
// if the user said they have more, then send prompts to read the next mail order input from user
getLabelData();
} // end if
} // end while
// successfully terminate the application
system.exit(0);
} // end main()
public static void getLabelData() {
nameAddressArray[0] = JOptionPane.showInputDialog("Enter title (Mr., Ms., Dr., etc.): ");
nameAddressArray[1] = JOptionPane.showInputDialog("Enter first name: ");
nameAddressArray[2] = JOptionPane.showInputDialog("Enter lastname: ");
nameAddressArray[3] = JOptionPane.showInputDialog("Enter street address: ");
nameAddressArray[4] = JOptionPane.showInputDialog("Enter city: ");
nameAddressArray[5] = JOptionPane.showInputDialog("Enter state (IL, MO, etc.): ");
nameAddressArray[6] = JOptionPane.showInputDialog("Enter zip (e.g., 62025): ");
numBoxesInput = JOptionPane.showInputDialog("Enter number of boxes in the order:");
numBoxes = Integer.parseInt(numBoxesInput);
}
} // end class
Я очень новичок в этом, так что я извиняюсь, если мой код полной катастрофой я просто Старается понять, почему это дает мне ошибку.
Вы не можете получить доступ к локальным переменным одного метода ('main') из другого метода. Локальные переменные существуют только в блоке, где они были объявлены. – RealSkeptic