Code Error Java?
public class Main {
public static void main(String[] args) {


    GUI gui = new GUI();
    
    }
    
   public static int fak (int n) {
        if (n == 0) {
            return 1;
        }
        return n * fak(n - 1);
    }
    
}

import javax.swing.*;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;


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


public class GUI extends JFrame {
    JButton button = new JButton("Berechnen");
    JLabel label = new JLabel("Bitte geben Sie die Zahl ein: ");
    JTextField textfield = new JTextField(2);
    JOptionPane popup = new JOptionPane();
    JPanel panel = new JPanel();
    
    public GUI () {
        setSize(300, 300);
        setTitle("Fakultätsrechner");
        setLayout(new FlowLayout());
        setVisible(true);
        
        panel.add(textfield);
        panel.add(label);
        panel.add(button);
        add(panel);
        
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setVisible(true);


        button.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                try {
                    String input = textfield.getText();
                    int number = Integer.parseInt(input);
                    int result = Main.fak(number);
                    JOptionPane.showMessageDialog(null, "Die Fakultät von " + number + " ist " + result);
                } catch (NumberFormatException ex) {
                    JOptionPane.showMessageDialog(null, "Bitte geben Sie eine gültige Ganzzahl ein.");
                }
            }
        });
        
    }





}

Error: java.lang.ClassNotFoundException: Main

Aber wieso findet er denn die Main-Klasse nicht? Verstehe ich nicht.

App, Java, Minecraft, Array, Code, Eclipse, Minecraft Server, Programmiersprache, Swing, game-development, Bukkit, Spigot, Java Swing, Android Studio
CPP Anfänger Code hilfe?
#include <iostream>
#include <cmath>
using namespace std;


double Addition(double zahl1, double zahl2)
{
    cout << "Gebe die erste Zahl ein, die addiert werden soll: ";
    cin >> zahl1;
    cout << "Gebe die zweite Zahl ein, die addiert werden soll: ";
    cin >> zahl2;
    double Summe = zahl1 + zahl2;
    cout << "Die Summe ist: " << Summe << endl;
    return zahl1 + zahl2;
}


double Subtraktion(double zahl1, double zahl2)
{
    cout << "Gebe die erste Zahl ein, die subtrahiert werden soll: ";
    cin >> zahl1;
    cout << "Gebe die zweite Zahl ein, die subtrahiert werden soll: ";
    cin >> zahl2;
    double Differenz = zahl1 - zahl2;
    cout << "Die Differenz ist: " << Differenz << endl;
    return zahl1 - zahl2;
}


double Multiplikation(double zahl1, double zahl2)
{
    cout << "Gebe die erste Zahl ein, die multipliziert werden soll: ";
    cin >> zahl1;
    cout << "Gebe die zweite Zahl ein, die multipliziert werden soll: ";
    cin >> zahl2;
    double Produkt = zahl1 * zahl2;
    cout << "Das Produkt ist: " << Produkt << endl;
    return zahl1 * zahl2;
}


double Division(double zahl1, double zahl2)
{
    cout << "Gebe die erste Zahl ein, die dividiert werden soll: ";
    cin >> zahl1;
    cout << "Gebe die zweite Zahl ein, die dividiert werden soll: ";
    cin >> zahl2;
    double Qoutient = zahl1 / zahl2;
    cout << "Der Quotient ist: " << Qoutient << endl;
    return zahl1 / zahl2;
}


double Potenz()
{
    double Basis;
    double Potenz;
    double Ergebnis;
    cout << "Gebe die Basis ein" << endl;
    cin >> Basis;
    cout << "Gebe die Potenz ein" << endl;
    cin >> Potenz;
    Ergebnis = pow(Basis, Potenz);
    cout << "Die Potenz ist: " << Ergebnis << endl;
    return pow(Basis, Potenz);
}


int main()
{
    char Rechenoperator;
    cout << "UNIVERSAL RECHNER" << endl;
    cout << "Bitte wähle die Rechenoperation aus" << endl;
    cout << "Addition(+)\nSubtraktion(-)\nMultiplikation(*)\nDivision(/)" << endl;
    cout << "Potenz(^)\nWurzel(<)\nProzent(%)" << endl;
    cin >> Rechenoperator;


    switch (Rechenoperator)
    {
    case '+':
        Addition(zahl1, zahl2);
        break;
    case '-':
        Subtraktion(zahl1, zahl2);
        break;
    case '*':
        Multiplikation(zahl1, zahl2);
        break;
    case '/':
        Division (zahl1, zahl2);
        break; 
    case '^':
        Potenz(Basis, Potenz);
        break;


    default:
        cout << "Ungültige Eingabe" << endl;
    }


    return 0;
}

main.cpp: In function ‘int main()’:
main.cpp:75:18: error: ‘zahl1’ was not declared in this scope
   75 |         Addition(zahl1, zahl2);
      |                  ^~~~~
main.cpp:75:25: error: ‘zahl2’ was not declared in this scope
   75 |         Addition(zahl1, zahl2);
      |                         ^~~~~
main.cpp:87:16: error: ‘Basis’ was not declared in this scope
   87 |         Potenz(Basis, Potenz);
Cplusplus, Array, Code, CPP, Programmiersprache, Visual Studio, Algorithmus

Meistgelesene Beiträge zum Thema Array