Results 1 to 2 of 2
  1. #1
    zlloyd1 is offline Member
    Join Date
    Nov 2012
    Rep Power

    Question Unsafe or unchecked errors in Command prompt issues

    I am trying to create a simple combobox in java, but my code cannot get past the compiler because of an error I do not understand. I have checked other related questions here, but could not find my specific problem. This is my program code:
    Java Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class ComboBoxDemo extends JFrame {
      private String[] languages = {
        "Java", "C++", "C", "Python",
        "JavaScript", "Perl", "Ruby", "C#"  };   
      private JTextField textfield1 = new JTextField
       ("Top Programming Languages : "); 
      private JTextField textfield2 = new JTextField(15);
      private JComboBox comboBox = new JComboBox();   
      private int count = 0; 
      public ComboBoxDemo() {
     for(int i = 0; i < languages.length; i++)
     comboBox.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent e) {
      textfield2.setText("You Selected : " +     
           ((JComboBox)e.getSource()).getSelectedItem()); }});  
     setLayout(new FlowLayout());
     add(comboBox);    }  
      public static void main(String[] args) {
     setFrame(new ComboBoxDemo(), 250, 150); } 
      public static void
      setFrame(final JFrame frame, final int width, final int height) {
     SwingUtilities.invokeLater(new Runnable() {
       public void run() {
         frame.setSize(width, height);
         frame.setVisible(true); }}); }}
    and as you can see, I have tried using the SuppressWarnings annotation here, but the error remains"
    Unsafe or unchecked errors in Command prompt issues-cmderrorz.jpg
    Can someon PLEASE explain what is going on here??

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Bali, Indonesia
    Rep Power

    Default Re: Unsafe or unchecked errors in Command prompt issues

    Why do you even need a SuppressWarnings annotation on array declaration anyway? As there is no warning there to be suppressed. It says duplicate because you use the annotation twice there. If you want to suppress multiple warnings then you need to pass the values as an array of strings.

    Java Code:
    @SuppressWarnings({"unchecked", "unsafe"})
    Last edited by wsaryada; 12-12-2012 at 09:04 AM.

Similar Threads

  1. Replies: 11
    Last Post: 04-16-2012, 05:12 PM
  2. How to fix the unchecked or unsafe opeartions error?
    By KillTheCube in forum New To Java
    Replies: 8
    Last Post: 12-18-2011, 12:52 PM
  3. Replies: 9
    Last Post: 05-11-2011, 04:31 PM
  4. Unchecked or unsafe operations warning
    By sky in forum New To Java
    Replies: 3
    Last Post: 12-06-2009, 03:41 AM
  5. Uses unchecked or unsafe operations message
    By Robbinz in forum New To Java
    Replies: 2
    Last Post: 12-06-2007, 10:56 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts