Cant find symbol. [X2]



  • To start Java's file. CMDI need to introduce these commans.

    javac PurchasesAmountApp.java
    java PurchasesAmountApp
    

    But if you write javac PurchasesAmountApp.javathat's a mistake.

    PurchasesAmountApp.java:10: error: cannot find symbol
            PurchasesAmountAppUI Application = new PurchasesAmountAppUI(WindowIcon, WindowTitle, WindowXY, WindowSize);
            ^
      symbol:   class PurchasesAmountAppUI
      location: class PurchasesAmountApp
    PurchasesAmountApp.java:10: error: cannot find symbol
            PurchasesAmountAppUI Application = new PurchasesAmountAppUI(WindowIcon, WindowTitle, WindowXY, WindowSize);
                                                   ^
      symbol:   class PurchasesAmountAppUI
      location: class PurchasesAmountApp
    2 errors
    

    PurchasesAmountApp.java

    package PurchasesAmount;
    

    public class PurchasesAmountApp {
    public static void main(String[] args) {
    final String WindowIcon = "PurchasesAmount\Resources\Icon.png";
    final String WindowTitle = "Вычислитель общей суммы покупок.";
    final int[] WindowXY = {250, 200};
    final int[] WindowSize = {500, 300};

        PurchasesAmountAppUI Application = new PurchasesAmountAppUI(WindowIcon, WindowTitle, WindowXY, WindowSize);
    }
    

    }

    PurchasesAmountAppMechanics.java

    package PurchasesAmount;

    public class PurchasesAmountAppMechanics {
    public int CountAmount(int[] Amounts) {
    int Total = 0;

        for(int Amount : Amounts) {
            Total += Amount;
        }
    
        return Total;
    }
    
    public int[] ConvertArrayElementsToInt(String[] Arr) {
        int[] ConvertedArray = new int[Arr.length];
    
        for(int i = 0; i < Arr.length; i++) {
            ConvertedArray[i] = Integer.parseInt(Arr[i]);
        }
    
        return ConvertedArray;
    }
    
    public int[] ParseAmounts(String Str) {
        String[] Amounts = Str.split(", ");
        int[] ConvertedAmounts = ConvertArrayElementsToInt(Amounts);
    
        return ConvertedAmounts;
    }
    
    public int Count(String Str) {
        try {
            int[] Amounts = ParseAmounts(Str);
            int Total = CountAmount(Amounts);
    
            return Total;
        }
    
        catch (Exception Err) {
            return -1;
        }
    }
    

    }

    PurchasesAmountAppUI. java

    package PurchasesAmount;

    import javax.swing.JFrame;

    import java.awt.Container;

    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;

    import java.awt.GridLayout;

    import javax.swing.ImageIcon;

    import javax.swing.JLabel;
    import javax.swing.JButton;
    import javax.swing.JTextField;

    import javax.swing.JOptionPane;

    public class PurchasesAmountAppUI extends JFrame {
    final private PurchasesAmountAppMechanics Mechanics = new PurchasesAmountAppMechanics();

    final private String PurchasesAmountLabelContent = "Сумма покупки !Amount.";
    
    final private JLabel PurchasesAmountLabel = new JLabel(PurchasesAmountLabelContent);
    final private JTextField AmountsTextField = new JTextField("10, 20, 20", 15);
    final private JButton CalculateTotalAmountButton = new JButton("Рассчитать сумму покупки.");
    final private JLabel AppVersionDataLabel = new JLabel("1.0, Beta.");
    
    public PurchasesAmountAppUI(String AppIcon, String AppTitle, int[] AppXY, int[] AppSize) {
        super(AppTitle);
    
        this.setBounds(AppXY[0], AppXY[1], AppSize[0], AppSize[1]);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
        ImageIcon WindowIcon = new ImageIcon(AppIcon);
        this.setIconImage(WindowIcon.getImage());
    
        Container Pane = this.getContentPane();
    
        GridLayout WindowLayout = new GridLayout(0, 1, 4, 6);
    
        Pane.setLayout(WindowLayout);
    
        AmountsTextField.setToolTipText("Введите сумму покупки, через запятую с пробелом. Пример: \"10, 10, 10, 10, 10\", разрешены только цифры, ничего другого.");
    
        CalculateTotalAmountButtonClicked CalculateTotalAmountButtonFunction = new CalculateTotalAmountButtonClicked();
    
        CalculateTotalAmountButton.addActionListener(CalculateTotalAmountButtonFunction);
    
        Pane.add(PurchasesAmountLabel);
        Pane.add(AmountsTextField);
        Pane.add(CalculateTotalAmountButton);
        Pane.add(AppVersionDataLabel);
    
        this.setVisible(true);
    }
    
    class CalculateTotalAmountButtonClicked implements ActionListener{
        public void actionPerformed(ActionEvent Event) {
            String Amounts = AmountsTextField.getText();
    
            int Calculated = Mechanics.Count(Amounts);
    
            if (Calculated == -1) {
                JOptionPane.showMessageDialog(null, "Вы ввели что-то не то. Наведите на текстовое поле мышку, и посмотрите краткую инструкцию.", "Вычислитель общей суммы покупок.", JOptionPane.INFORMATION_MESSAGE);
    
            } else {
                PurchasesAmountLabel.setText(PurchasesAmountLabelContent.replace("!Amount", Calculated + ""));
            }
        }
    }
    

    }

    https://drive.google.com/drive/folders/1tSCT4_rC367vOl-G8qs5KzpnElou2S8N?usp=sharing ♪

    What do we do?



  • First, we need to point out the director where the compiler is launched. javac and medium of implementation java

    The compilation should also indicate the director by the key. -dto which the compiled .class files.

    Suppose the original code of the package. PurchasesAmount lies in the directory. tmp\srcThen he's successfully teamed up.

    F:\tmp\src>javac -d ..\classes PurchasesAmount\PurchasesAmountApp.java
    

    Compilation results:

    F:\tmp\src>dir /s ..\classes
    

    Directory of F:\tmp\classes

    2021-11-12 19:09 <DIR> .
    2021-11-12 19:09 <DIR> ..
    2021-11-12 19:09 <DIR> PurchasesAmount
    0 File(s) 0 bytes

    Directory of F:\tmp\classes\PurchasesAmount

    2021-11-12 19:09 <DIR> .
    2021-11-12 19:09 <DIR> ..
    2021-11-12 19:09 625 PurchasesAmountApp.class
    2021-11-12 19:09 980 PurchasesAmountAppMechanics.class
    2021-11-12 19:09 2,339 PurchasesAmountAppUI$CalculateTotalAmountButtonClicked.class
    2021-11-12 19:09 2,529 PurchasesAmountAppUI.class
    4 File(s) 6,473 bytes

    For start-up java She needs to indicate the way to class (CLASSPATH), with a parameter -cp♪ In addition, it should be remembered that a full class name, including the name of the package, will be required for launch:

    F:\tmp\src>cd ..

    F:\tmp>java -cp .\classes PurchasesAmount.PurchasesAmountApp


Log in to reply
 

Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2