Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在eclipse中获取未知错误。在cmd中运行完美_Java_Eclipse_Compilation_Cmd - Fatal编程技术网

Java 在eclipse中获取未知错误。在cmd中运行完美

Java 在eclipse中获取未知错误。在cmd中运行完美,java,eclipse,compilation,cmd,Java,Eclipse,Compilation,Cmd,所以,我复制粘贴到记事本+,并保存在其他地方。 然后,我在CMD中尝试了它,代码运行得很顺利。请提供帮助?删除“@Override”会起作用删除@Orverride应该可以解决问题,因为@Override表示您在程序的其他地方使用了相同的方法,并且您希望“覆盖”它,而在本例中,您不希望“覆盖”它,而是希望创建它,而不是覆盖它。要了解有关如何使用@Override方法的更多信息,请不要让我们猜测或滚动搜索,第413行是什么?顺便说一句,通常eclipse应该在编辑器中显示问题(红色标记),并告诉您

所以,我复制粘贴到记事本+,并保存在其他地方。
然后,我在CMD中尝试了它,代码运行得很顺利。请提供帮助?

删除“@Override”会起作用

删除
@Orverride
应该可以解决问题,因为
@Override
表示您在程序的其他地方使用了相同的方法,并且您希望“覆盖”它,而在本例中,您不希望“覆盖”它,而是希望创建它,而不是覆盖它。要了解有关如何使用
@Override
方法的更多信息,请不要让我们猜测或滚动搜索,第413行是什么?顺便说一句,通常eclipse应该在编辑器中显示问题(红色标记),并告诉您问题所在。“未解决的编译问题”表示代码中存在编译错误(即语法错误)你没有修好。此外,大量使用空
catch
块也非常糟糕。代码抛出的任何异常都会悄然消失,并且会出现无法解释的奇怪行为。不要这样做。413是主(字符串args[])行。它在类声明行显示此警告:可序列化类ScientificCalc不会声明longThank You kind sir.类型的静态最终SerialVersionId字段。。我一定会仔细阅读的
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class ScientificCalc extends JFrame implements ActionListener
{

    JPanel[] row = new JPanel[8];
    JPanel[] row2 = new JPanel[3];
    JButton[] button = new JButton[27];
    String[] buttonString = {   "7", "8", "9", "+", "√",
                                "4", "5", "6", "-", "³√",
                                "1", "2", "3", "*", "ⁿ√",
                                "0", ".", "/", "±",
                                "=", "sin", "cos", "tan",
                                "Clear", "x²", "x³", "xⁿ"};

    int[] dimW = {300, 54, 100, 109};
    int[] dimH = {35, 48, 100};
        Dimension displayDimension = new Dimension(dimW[0], dimH[0]);
        Dimension regularDimension = new Dimension(dimW[1], dimH[1]);
        Dimension rColumnDimension = new Dimension(dimW[2], dimH[1]);
        Dimension zeroButDimension = new Dimension(dimW[3], dimH[1]);
    boolean[] function = new boolean[4];
    double[] temporary = {0, 0};
    JTextArea display = new JTextArea (1,20);
    Font font = new Font("Comic Sans MS", Font.BOLD, 14);


    ScientificCalc()
    {
        super("Scientific Calculator");
        setDesign();
        setSize(500, 400);
        setResizable(true);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        GridLayout grid = new GridLayout(7,5);
        setLayout(grid);

        for (int i = 0; i < 4; i++)
        {
            function[i] = false;
        }

        FlowLayout f1 = new FlowLayout(FlowLayout.CENTER);
        FlowLayout f2 = new FlowLayout(FlowLayout.CENTER,1,1);

        for(int i = 0; i < 8; i++)
        {   
            row[i] = new JPanel();
        }

        row[0].setLayout(f1);

        for(int i = 1; i < 8; i++)
        {   
            row[i].setLayout(f2);
        }

        for(int i = 0; i < 27; i++) 
        {
            button[i] = new JButton();
            button[i].setText(buttonString[i]);
            button[i].setFont(font);
            button[i].addActionListener(this);
        }

        display.setFont(font);
        display.setEditable(false);


        display.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        display.setPreferredSize(displayDimension);

        for(int i = 0; i < 15; i++)
        {   
            button[i].setPreferredSize(regularDimension);
        }

        for(int i = 15; i < 27; i++)
        {   
            button[i].setPreferredSize(regularDimension);
        }

        button[15].setPreferredSize(zeroButDimension);
        button[19].setPreferredSize(zeroButDimension);
        button[23].setPreferredSize(zeroButDimension);


        row[0].add(display);
        add(row[0]);


        for(int i = 0; i < 5; i++)
        {   
            row[1].add(button[i]);
            add(row[1]);
        }

        for(int i = 5; i < 10; i++)
        {
            row[2].add(button[i]);
            add(row[2]);
        }

        for(int i = 10; i < 15; i++)
        { 
            row[3].add(button[i]);
            add(row[3]);
        }

        row[4].add(button[15]);

        for(int i = 15; i < 19 ; i++)
        {
            row[4].add(button[i]);
            add(row[4]);
        }

        row[5].add(button[19]);
        for(int i = 20; i < 24 ; i++)
        {
            row[5].add(button[i]);
            add(row[5]);
        }


        row[6].add(button[23]);
        for(int i = 24; i < 27; i++)
        {
            row[6].add(button[i]);
            add(row[6]);    
        }

        setVisible(true);
    }


    public void clear()
    {

        try 
        {
            display.setText("");
            for(int i = 0; i < 4; i++)
                function[i] = false;
            for(int i = 0; i < 2; i++)
                temporary[i] = 0;
        } catch(NullPointerException e) 
        {  
        }
    }


    public void getSqrt() 
    {
        try {
            double value = Math.sqrt(Double.parseDouble(display.getText()));
            display.setText(Double.toString(value));
        } catch(NumberFormatException e) {
        }
    }


    public void getCbrt() 
    {
        try {
            double value = Math.cbrt(Double.parseDouble(display.getText()));
            display.setText(Double.toString(value));
        } catch(NumberFormatException e) {
        }
    }


    public void getNthRoot()
    {
        try {
            double result = 0;
            temporary[1] = Double.parseDouble(display.getText());
            result = Math.pow(temporary[0], (1/temporary[1]));
            display.setText(Double.toString(result));
        } catch(NumberFormatException e) {
        }
    }


    public void getPosNeg() 
    {
        try {
            double value = Double.parseDouble(display.getText());
            if(value != 0) {
                value = value * (-1);
                display.setText(Double.toString(value));
            }
            else {
            }
        } catch(NumberFormatException e) {
        }
    }


    public void getSqr()
    {
        try
        {
            double value = Math.pow(Double.parseDouble(display.getText()), 2);
            display.setText(Double.toString(value));
        }   catch(NumberFormatException e)
            {
            }

    }



    public void getCube()
    {
        try
        {
            double value = Math.pow(Double.parseDouble(display.getText()), 3);
            display.setText(Double.toString(value));
        }   catch(NumberFormatException e)
            {
            }

    }



    public void getNthPow()
    {
        try
        {
            double result = 0;
            temporary[1] = Double.parseDouble(display.getText());
            result = Math.pow(temporary[0], temporary[1]);
            display.setText(Double.toString(result));
        }   catch(NumberFormatException e)
            {

            }
    }


    public void getSin()
    {
        try
        {
            double value = Math.sin(Double.parseDouble(display.getText()));
            display.setText(Double.toString(value));
        }   catch(NumberFormatException e)
            {
            }
    }


    public void getCos()
    {
        try
        {
            double value = Math.sin(Double.parseDouble(display.getText()));
            display.setText(Double.toString(value));
        }   catch(NumberFormatException e)
            {
            }
    }


    public void getTan()
    {
        try
        {
            double value = Math.sin(Double.parseDouble(display.getText()));
            display.setText(Double.toString(value));
        }   catch(NumberFormatException e)
            {
            }
    }



    public void getResult() {
        double result = 0;
        temporary[1] = Double.parseDouble(display.getText());
        String temp0 = Double.toString(temporary[0]);
        String temp1 = Double.toString(temporary[1]);
        try {
            if(temp0.contains("-")) {
                String[] temp00 = temp0.split("-", 2);
                temporary[0] = (Double.parseDouble(temp00[1]) * -1);
            }
            if(temp1.contains("-")) {
                String[] temp11 = temp1.split("-", 2);
                temporary[1] = (Double.parseDouble(temp11[1]) * -1);
            }
        } catch(ArrayIndexOutOfBoundsException e) {
        }
        try {
            if(function[2] == true)
                result = temporary[0] * temporary[1];
            else if(function[3] == true)
                result = temporary[0] / temporary[1];
            else if(function[0] == true)
                result = temporary[0] + temporary[1];
            else if(function[1] == true)
                result = temporary[0] - temporary[1];
            display.setText(Double.toString(result));
            for(int i = 0; i < 4; i++)
                function[i] = false;
        } catch(NumberFormatException e) {
        }
    }



    @Override
    public void actionPerformed(ActionEvent ae) 
    {
        if(ae.getSource() == button[0])
            display.append("7");
        if(ae.getSource() == button[1])
            display.append("8");
        if(ae.getSource() == button[2])
            display.append("9");
        if(ae.getSource() == button[3]) 
        {
            //add function[0]
            temporary[0] = Double.parseDouble(display.getText());
            function[0] = true;
            display.setText("");
        }

        if(ae.getSource() == button[4])
            getSqrt();
        if(ae.getSource() == button[5])
            display.append("4");
        if(ae.getSource() == button[6])
            display.append("5");
        if(ae.getSource() == button[7])
            display.append("6");
        if(ae.getSource() == button[8]) 
        {
            //subtract function[1]
            temporary[0] = Double.parseDouble(display.getText());
            function[1] = true;
            display.setText("");
        }

        if(ae.getSource() == button[9])
            getCbrt();
        if(ae.getSource() == button[10])
            display.append("1");
        if(ae.getSource() == button[11])
            display.append("2");
        if(ae.getSource() == button[12])
            display.append("3");
        if(ae.getSource() == button[13]) 
        {
            //multiply function[2]
            temporary[0] = Double.parseDouble(display.getText());
            function[2] = true;
            display.setText("");
        }

        if(ae.getSource() == button[14])
        {
            temporary[0] = Double.parseDouble(display.getText());
            display.setText("");
            getNthRoot();
        }

        if(ae.getSource() == button[15])
            display.append("0");
        if(ae.getSource() == button[16])
            display.append(".");
        if(ae.getSource() == button[17]) 
        {
            //divide function[3]
            temporary[0] = Double.parseDouble(display.getText());
            function[3] = true;
            display.setText("");
        }

        if(ae.getSource() == button[18])
            getPosNeg();
        if(ae.getSource() == button[19])
            getResult();
        if(ae.getSource() == button[20])
            getSin();
        if(ae.getSource() == button[21])
            getCos();
        if(ae.getSource() == button[22])
            getTan();
        if(ae.getSource() == button[23])
            clear();
        if(ae.getSource() == button[24])
            getSqr();
        if(ae.getSource() == button[25])
            getCube();
        if(ae.getSource() == button[26])
            getNthPow();
    }


    public final void setDesign() {
        try {
            UIManager.setLookAndFeel(
                    "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
        } catch(Exception e) {   
        }
    }

    public static void main(String[] args) 
    {
        new ScientificCalc();
    }

}
Exception in thread "main" java.lang.Error: Unresolved compilation problem: 

    at ScientificCalc.main(ScientificCalc.java:413)