2016-05-26 11 views
0

こんにちは私は現在、コードでエラーが発生しています。これは '内部クラスMain.Testの無効な静的宣言です。 修飾子' static 'は定数変数の宣言でのみ許可されています'私はこのエラーがなぜ発生したのか理解していますが、何を変更する必要があるかを具体的に把握することはできません。 - 私はいくつかの他の記事で見たように、私は私の他のクラスには、静的作ってみましたが、これはまだここ 不正な静的宣言

を動作しませんでしたが、私のコードです:

public class Main extends JFrame { 
public Main() { 
    String username = System.getProperty("user.name"); 
    JFrame.setDefaultLookAndFeelDecorated(true); 
    JFrame frame = new JFrame("Projects Design"); 
    frame.setLayout(new FlowLayout()); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    String text = username; 
    JTextArea textAreal = new JTextArea(text, 10, 10); 
    textAreal.setPreferredSize(new Dimension(400, 400)); 
    textAreal.setLineWrap(true); 
    textAreal.setEditable(false); 
    frame.add(textAreal); 
    frame.pack(); 
    frame.setVisible(true); 
    } 

    public class Test extends JFrame{ 
    JComboBox jc = new JComboBox(); 
    JPanel panel = new JPanel(); 
    Connection con; 
    Statement st; 
    ResultSet rs; 
    public Test() { 
     this.setSize(400, 400); 
     this.setLocationRelativeTo(null); 
     this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     try{ 
     con = DriverManager.getConnection("Removed for obvious reasons"); 
     st = con.createStatement(); 
     String s = "SELECT Code FROM users WHERE id="12"; 
     rs = st.executeQuery(s); 
     while(rs.next()) 
     { 
      jc.addItem(rs.getString(1)); 
     } 
     }catch (Exception e) { 
     JOptionPane.showMessageDialog(null, "ERROR"); 
     }finally{ 
     try{ 
     st.close(); 
     rs.close(); 
     con.close(); 
     }catch(Exception e){ 
     JOptionPane.showMessageDialog(null, "ERROR CLOSE"); 
     } 
     } 
     panel.add(jc); 
     this.getContentPane().add(panel); 
     this.setVisible(true); 

     } 

    public static void main(String[] args) { 
    Main rectProg = new Main(); 
    new Test(); 
    } 
+0

ええ私はすでにあなたがリンクしているこの記事を見ましたが、これは私のためにはうまくいかなかったので、他に何ができるのか分かりませんでした。 –

答えて

0

ああ、私はそれを考え出した、私は私の静的なクラスを移動しました内部クラスの内側に静的メソッドがあるので、内部クラスの外側にあります。助けてくれてありがとう

関連する問題