Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/353.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
无法在netbeans中编译java程序_Java_Netbeans_Symbols - Fatal编程技术网

无法在netbeans中编译java程序

无法在netbeans中编译java程序,java,netbeans,symbols,Java,Netbeans,Symbols,我已经创建了一个java程序,但无法在netbeans中运行。当我试图从另一个文件导入名为invice的类时。这是一个错误的说法 error: cannot find symbol invice invc=new invice(); 程序如下。我已经在一个名为Invicedemo的类中编写了主函数 package invicedemo; public class Invicedemo { public static void main(String[] args) {

我已经创建了一个java程序,但无法在netbeans中运行。当我试图从另一个文件导入名为invice的类时。这是一个错误的说法

error: cannot find symbol
invice invc=new invice();
程序如下。我已经在一个名为Invicedemo的类中编写了主函数

package invicedemo;
    public class Invicedemo {
        public static void main(String[] args) {
                    invice invc=new invice();
            invc.setSize(300,250);
            invc.setTitle("party memo");
            invc.setVisible(true);
        }

    }
我试图导入的类与文件名invice.java位于同一个包中

import java.awt.*;
import java.sql.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.*;

public class invice extends JFrame implements ActionListener, KeyListener, FocusListener {

    JTextField tf, tf1, tf2, tf3;
    JButton bt, bt1;
    JLabel lb, lb1, lb2, lb3;
    Container cn;

    public invice() {
        cn = getContentPane();
        cn.setLayout(null);

        lb = new JLabel("Bill No.:");
        lb.setBounds(10, 10, 70, 25);
        cn.add(lb);
        tf = new JTextField();
        tf.setBounds(100, 10, 150, 25);
        cn.add(tf);

        lb1 = new JLabel("Party Name:");
        lb1.setBounds(10, 40, 70, 25);
        cn.add(lb1);
        tf1 = new JTextField();
        tf1.setBounds(100, 40, 150, 25);
        cn.add(tf1);

        lb2 = new JLabel("Date:");
        lb2.setBounds(10, 70, 70, 25);
        cn.add(lb2);
        tf2 = new JTextField();
        tf2.setBounds(100, 70, 150, 25);
        cn.add(tf2);

        lb3 = new JLabel("Gr No.:");
        lb3.setBounds(10, 100, 70, 25);
        cn.add(lb3);
        tf3 = new JTextField();
        tf3.setBounds(100, 100, 150, 25);
        cn.add(tf3);

        bt = new JButton("Store:");
        bt.setBounds(30, 160, 70, 25);
        cn.add(bt);

        bt1 = new JButton("Cancel:");
        bt1.setBounds(150, 160, 80, 25);
        cn.add(bt1);

        tf.addKeyListener(this);
        tf1.addKeyListener(this);
        tf2.addKeyListener(this);
        tf.addFocusListener(this);
        tf1.addFocusListener(this);
        tf2.addFocusListener(this);

        bt.addKeyListener(this);
        bt.addFocusListener(this);

        tf3.addKeyListener(this);
        tf3.addFocusListener(this);

        bt1.addKeyListener(this);
        bt1.addFocusListener(this);
        bt.addActionListener(this);
        bt1.addActionListener(this);
    }

    public void actionPerformed(ActionEvent ae) {

        if (ae.getSource() == bt) {

            String party_name = tf.getText();
            String date = tf1.getText();
            String gr_no = tf2.getText();
            String Sno = tf3.getText();

            try {
                Class.forName("com.mysql.jdbc.Driver");
                Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "asiya");
                Statement st = con.createStatement();
                st.executeUpdate("Insert into invis values('" + Sno + "','" + party_name + "', '" + date + "', '" + gr_no + "')");

                JOptionPane.showMessageDialog(cn, "your data is successfully store", "storage", JOptionPane.INFORMATION_MESSAGE);

            } catch (Exception e) {
                JOptionPane.showMessageDialog(cn, e, "storage", JOptionPane.INFORMATION_MESSAGE);
            }

        }
        if (ae.getSource() == bt1) {
            tf.setText("");
            tf1.setText("");
            tf2.setText("");
            tf3.setText("");
        }
    }

    public void keyPressed(KeyEvent ke) {
        if (ke.getSource() == tf && ke.getKeyCode() == KeyEvent.VK_ENTER) {
            tf1.requestFocus();
        }

        if (ke.getSource() == tf1 && ke.getKeyCode() == KeyEvent.VK_ENTER) {
            tf2.requestFocus();
        }

        if (ke.getSource() == tf2 && ke.getKeyCode() == KeyEvent.VK_ENTER) {
            tf3.requestFocus();
        }
        if (ke.getSource() == tf3 && ke.getKeyCode() == KeyEvent.VK_ENTER) {
            bt.requestFocus();
        }

        if (ke.getSource() == bt && ke.getKeyCode() == KeyEvent.VK_ENTER) {
            bt1.requestFocus();

            tf.setText("");
            tf1.setText("");
            tf2.setText("");
        }

    }

    public void keyTyped(KeyEvent ke) {
    }

    public void keyReleased(KeyEvent ke) {
    }

    public void focusGained(FocusEvent fe) {
    }

    public void focusLost(FocusEvent fe) {
    }
}

谁能告诉我我犯了什么错误。

你只是在第二节课上忘记了
包的声明:

package invicedemo;
class invice ... { ... }

因为两个类不在同一个包中。您必须
导入
您的类
invice
您的类
invice
中的语句?这可能就是问题所在。顺便说一句:坚持Java代码惯例,编写类名
CamelCase
。请阅读@JigarJoshi,它们在同一个包中。@请参阅解决我问题的大师,你能给出答案吗,这样我就可以接受了。是的,我会遵守你提到的惯例。谢谢:)为什么这被否决了?@JigarJoshi问得好。现在,人们的投票速度有点快。。。我不在乎。投票应该是绝对的,而不是相对的。若你们认为这个答案的投票率很高,你们认为它不值得投票。“不投票比不投票更好。”JigarJoshi我知道有时很难正确投票。但毕竟,如果一个答案没有提供答案,或者它本身是错误的或误导性的,那么它应该得到否决票。没那么难,嗯?