java - java编译错误: -Xlint causing problems

标签 java netbeans compiler-errors

基本上,有2个框架:“StartUpFrame”和“ActivityScreen”
StartUpFrame是使用纯 Netbeans GUI 制作的,而ActivityScreen是通过编码而不使用任何Netbeans GUI 制作的。

在StartUpFrame上,当我按下“ Activity 列表”按钮时,应将框架切换到ActivityScreen,这应该是非常简单的操作。

但是,当我自己编译ActivityScreen时,它给了我一些警告,类似于:

“注意:F:\ Java \ Lab 8 \ Lab8.java使用未经检查或不安全的操作。注意:请使用-Xlint:unchecked重新编译以获取详细信息。”,
但是该文件仍然可以编译。

当我尝试编译StartUpFrame时,该错误似乎导致按钮操作出现问题,无法正确调用该类

我只是不知道是什么问题。

StartUpFrame.java

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

public class StartUpFrame extends JFrame
{

    //Creates new form StartUpFrame
    public StartUpFrame() 
    {
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        title = new javax.swing.JLabel();
        btnActivities = new javax.swing.JButton();
        ButtonExit = new javax.swing.JButton();
        btnStudents = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        title.setFont(new java.awt.Font("Arial", 0, 48)); // NOI18N
        title.setText("ASA Magement Program");

        btnActivities.setFont(new java.awt.Font("Arial", 0, 24)); // NOI18N
        btnActivities.setText("List of Activities");
        btnActivities.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnActivitiesActionPerformed(evt);
            }
        });

        ButtonExit.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        ButtonExit.setText("Exit");
        ButtonExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButtonExitActionPerformed(evt);
            }
        });

        btnStudents.setFont(new java.awt.Font("Arial", 0, 24)); // NOI18N
        btnStudents.setText("List of All Students");
        btnStudents.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnStudentsActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap(233, Short.MAX_VALUE)
                .addComponent(btnActivities)
                .addGap(232, 232, 232))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(62, 62, 62)
                        .addComponent(title))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(213, 213, 213)
                        .addComponent(btnStudents)))
                .addGap(0, 0, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(258, 258, 258)
                .addComponent(ButtonExit, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(title)
                .addGap(103, 103, 103)
                .addComponent(btnActivities)
                .addGap(61, 61, 61)
                .addComponent(btnStudents)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 110, Short.MAX_VALUE)
                .addComponent(ButtonExit, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        pack();
        setLocationRelativeTo(null);
    }// </editor-fold>//GEN-END:initComponents


    private void ButtonExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButtonExitActionPerformed
        System.exit(0);
    }//GEN-LAST:event_ButtonExitActionPerformed

    private void btnActivitiesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnActivitiesActionPerformed

                ActivityScreen AS = new ActivityScreen();
                AS.setVisible(true);
                setVisible(false);

    }//GEN-LAST:event_btnActivitiesActionPerformed

    private void btnStudentsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnStudentsActionPerformed


            StudentScreen SS = new StudentScreen();
            SS.setVisible(true);
            setVisible(false);

    }//GEN-LAST:event_btnStudentsActionPerformed

//the command line arguments
    public static void main(String args[]) 
    {
    // Create and display the form
        java.awt.EventQueue.invokeLater(new Runnable() 
        {
            public void run()
            {
                new StartUpFrame().setVisible(true);
            }
        });
    }

    //note to self: NEED TO REMOVE "JAVAX.SWING."
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ButtonExit;
    private javax.swing.JButton btnActivities;
    private javax.swing.JButton btnStudents;
    private javax.swing.JLabel title;
    // End of variables declaration//GEN-END:variables
}

ActivityScreen.java
       import java.io.*;
    import java.util.*;
    import java.util.List;
    import javax.swing.JTable;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.Component;
    import java.awt.Container;
    import javax.swing.BoxLayout;
    import javax.swing.JButton;
    import java.awt.event.ActionEvent;
        import java.awt.event.ActionListener;



    class MyFrame extends javax.swing.JFrame
    {


     //Object[][] cell_value = {  {"Sunday","Activity1","Activity2","Activity3"},  {"Monday","Activity4","Activity5","Activity6"},  {"Tuesday","Activity7","Activity8",""}};
     Object[][] cell_value = new Object[0][5];


     //String ColName[] = { "Title1", "Title2", "Title3", "Title4"};
       String ColName[] = new String [5];

     MyFrame()
     {
        try{ 
                String s = "";
                int n = 0;
                int m = 0;
                int rowcount = 0;
                BufferedReader in = new BufferedReader(new FileReader("Days.dat"));

                List list = Collections.synchronizedList(new LinkedList());
                while ( (s = in.readLine()) != null ) { 
                    if(!s.equals(""))
                    {
                        //System.out.println(s); 
                        list.add(s);
                        if(s.equals("Sunday")) { ColName[0]=s; }
                        else if(s.equals("Monday")) { ColName[1]=s; }
                        else if(s.equals("Tuesday")) { ColName[2]=s; }
                                            else if(s.equals("Wednesday")) { ColName[3]=s; }
                                            else if(s.equals("Thursday")) { ColName[4]=s; }
                        else {rowcount ++;}
                    }
                } 
                in.close(); 



            cell_value = new Object[rowcount][5];
                    for(int i = 0

    ; i< list.size();i++)
                {
                    if(list.get(i).equals("Sunday")) 
                    { n=0; m=0; }
                    else if(list.get(i).equals("Monday")) 
                    { n=1; m=0; }
                    else if(list.get(i).equals("Tuesday")) 
                    { n=2; m=0; }
                                    else if(list.get(i).equals("Wednesday")) 
                    { n=3; m=0; }
                                    else if(list.get(i).equals("Thursday")) 
                    { n=4; m=0; }
                    else 
                    { 
                        cell_value[m][n]=list.get(i);
                        m++;
                    }

                }

        } catch (IOException e) { 
            e.printStackTrace(); 
        }  

        Container contentPane = this.getContentPane();
        setTitle("Activity Screen");
        setSize(1000, 500);    


        JTable table = new JTable(cell_value, ColName);


          JLabel lblTitle = new JLabel("Activities");
          lblTitle.setFont(new java.awt.Font("Arial", 1, 24));

          JButton btnSave = new JButton("Save");
          JButton btnView = new JButton("View");
          JButton btnAdd = new JButton("Add");
          JButton btnRemove = new JButton("Remove");
          JButton btnBack = new JButton("Back");

          btnBack.addActionListener(new ActionListener() {

                public void actionPerformed(ActionEvent e)
                {
                    //Execute when button is pressed
                    StartUpFrame SUF = new StartUpFrame();
                    SUF.setVisible(true);
                    setVisible(false);
                }
            });  

           btnView.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e)
            {
             ViewActivity VA = new ViewActivity();
             VA.setVisible(true);
            }
        });  

        btnAdd.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent e)
            {
             AddActivity AA = new AddActivity();
             AA.setVisible(true);
            }
        });  



      //Lay out the label and scroll pane from top to bottom.
      contentPane.add(lblTitle, BorderLayout.PAGE_START);

      contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
      table.setAlignmentX(Component.CENTER_ALIGNMENT);
      contentPane.add(Box.createRigidArea(new Dimension(0,20)));
      contentPane.add(table);
      add(new JScrollPane(table));

      //Lay out the buttons from left to right.
      JPanel buttonPane = new JPanel();
      buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));

      buttonPane.add(Box.createHorizontalGlue());
      buttonPane.add(btnSave);
      buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
      buttonPane.add(btnView);
      buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
      buttonPane.add(btnAdd);
      buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
      buttonPane.add(btnRemove);
      buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
      buttonPane.add(btnBack);

      contentPane.add(buttonPane, BorderLayout.PAGE_END);

      setVisible(true);
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      table.setCellSelectionEnabled(true);

 }  


}



class ActivityScreen
{
 public static void main(String[] args)
 {
   new MyFrame();
 }
}

days.dat文件
Sunday
Advanced Open Water Dive Certificate
Sailing
Generation Next

Monday
Helping Hands
Beach Touch Rugby
Running Club
Yoga Club
Tennis Lessons

Tuesday
Recycling Club
Best Buddies
Crochet Club
Movie Club
Shooting Club

Wednesday
Table Tennis
Modern Dance
Contemporary Dance
Gavel Club

Thursday
Cooking
Gym Training

最佳答案

您的LinkedList是字符串。如果您没有错误地将另一个类对象放入LinkedList<String>中,则将LinkedList放入Java可以检查编译。或在未检查操作的方法前添加@SuppressWarnings("unchecked")

关于java - java编译错误: -Xlint causing problems,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15307668/

相关文章:

c++ - constexpr 默认的默认构造函数

c# - 如果结构属性在列表中,为什么不能更改它们?

java - 如何包含 Wicket Palette 的默认 css 文件?

java - netbeans 配置文件中的调用计数

php - 无法使用 NetBeans IDE (8.1) 设置 Symfony2 框架

Python pyinstaller 编译代码失败,返回 "The ' 找不到密码学的分布,应用程序需要它”

java - 32位操作系统和64位操作系统之间java.net.InetAddress类有什么区别

java - 用于文本 block 对齐的 IntelliJ Java 代码样式

java - 如何通过 Java 写入 XML 并通过 HTML 显示它?

java - REST 网络服务 : Server responding with a JAX-B error to GET