Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7796643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:25:52+00:00 2026-06-01T23:25:52+00:00

I am completing a lab assignment for school and get this error when I

  • 0

I am completing a lab assignment for school and get this error when I compile. The program runs fine, bit would like to fix what is causing the error. The program code and the complete error is below. Thanks as always!

Error:
Note: F:\Java\Lab 8\Lab8.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Code:

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


   public class Lab8 extends JFrame {
       public Lab8()
           {

           // Create an array of Strings for age ranges
           String[] ageRanges = {"Under 20", "20-29", "30-39", "40-49", "50-59", "60 and Above"};
           JComboBox jcbo = new JComboBox(ageRanges);

           // Create an array of String destinations
           String[] destination = {"Mercury", "Venus", "Moon", "Mars", "Jupiter / Europa", "Saturn / Triton", "Pluto + Sharon"};
           JList jlst = new JList();

           // Declare radio buttons
           JRadioButton jrbMonday, jrbTuesday, jrbWednesday, jrbThursday, jrbFriday;

           // Create a textfield
           JTextField jMsg = new JTextField(10);


           // Create panel to hold label and textbox.
           JPanel p1 = new JPanel();
           p1.setLayout(new BorderLayout(5,0));
           p1.add(new JLabel("Name: "), BorderLayout.WEST);
           p1.add(new JTextField(20), BorderLayout.CENTER);
           jMsg.setHorizontalAlignment(JTextField.LEFT);


           // Create combobox panel.
           JPanel p2 = new JPanel();
           p2.setLayout(new GridLayout(2,0,5,5));
           p2.add(p1, BorderLayout.NORTH);
           p2.add(new JComboBox(ageRanges), BorderLayout.CENTER);
               p2.setBorder(new TitledBorder("Passenger Name & Age Range"));


           //Create listbox panel.
           JPanel p3 = new JPanel();
           p3.setLayout(new GridLayout(1, 0));
           p3.add(new JList(destination));
               p3.setBorder(new TitledBorder("Destinations"));


           // Create a new panel to hold radio buttons.
               JPanel r1 = new JPanel();
           r1.setLayout(new GridLayout(3,2));
           r1.add(jrbMonday = new JRadioButton("Monday"));
           r1.add(jrbTuesday = new JRadioButton("Tuesday"));
           r1.add(jrbWednesday = new JRadioButton("Wednesday"));
           r1.add(jrbThursday = new JRadioButton("Thursday"));
           r1.add(jrbFriday = new JRadioButton("Friday"));
           r1.setBorder(new TitledBorder("Departure Days"));


           // Create a radio button group to group five buttons
           ButtonGroup group = new ButtonGroup();
           group.add(jrbMonday);
           group.add(jrbTuesday);
           group.add(jrbWednesday);
           group.add(jrbThursday);
           group.add(jrbFriday);


           // Create grid to hold contents
           JPanel pMain = new JPanel();
           pMain.setLayout(new BorderLayout(5,0));
           add(r1, BorderLayout.CENTER);
           add(p2, BorderLayout.NORTH);
           add(p3, BorderLayout. EAST);

}


public static void main(String[] args)
       {
           Lab8 frame = new Lab8();
           frame.pack();
           frame.setTitle("Lab 8 Application");
           frame.setLocationRelativeTo(null); // Center the frame
           frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           frame.setSize(425, 275);
           frame.setVisible(true);
        }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:25:53+00:00Added an answer on June 1, 2026 at 11:25 pm

    What this means is that the Java compiler has noticed some potentially unsafe issues with your code and is warning you. These issues are normally very trivial and you could carry on with them; especially since this is school work. But to find the issues, you should compile again with: javac -Xlint:unchecked Lab8.java like the compiler says.

    The issues in this file are that you haven’t specified the type of object the JComboBox and JList are dealing with. Since you are only dealing with Strings in the JComboBox and JList, you should specify that. Read up on Java generics and this for more information.

    Change

    String[] ageRanges = {"Under 20", "20-29", "30-39", "40-49", "50-59", "60 and Above"};
    JComboBox jcbo = new JComboBox(ageRanges);
    

    to

    String[] ageRanges = {"Under 20", "20-29", "30-39", "40-49", "50-59", "60 and Above"};
    JComboBox<String> jcbo = new JComboBox<String>(ageRanges);
    

    Also change:

    p2.add(new JComboBox(ageRanges), BorderLayout.CENTER);
    p2.setBorder(new TitledBorder("Passenger Name & Age Range"));
    

    to

    p2.add(new JComboBox<String>(ageRanges), BorderLayout.CENTER);
    p2.setBorder(new TitledBorder("Passenger Name & Age Range"));
    

    Finally change

    //Create listbox panel.
    JPanel p3 = new JPanel();
    p3.setLayout(new GridLayout(1, 0));
    p3.add(new JList(destination));
    

    to

    //Create listbox panel.
    JPanel p3 = new JPanel();
    p3.setLayout(new GridLayout(1, 0));
    p3.add(new JList<String>(destination));
    

    Edit:

    Not recommended for production code, but to bypass these warnings use:

    @SuppressWarnings("unchecked") 
    

    Just add this above any method that makes unsafe operations. For instance, I think you could put it above your main method in this code like so:

    @SuppressWarnings("unchecked") 
    public static void main(String[] args) {
    ...
    

    This would suppress the warnings.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I used code like this: (defvar my-defvar test) (completing-read input: '(1 2 my-defvar)) Then
I'm trying to get a CSS animation property to stay after completing, is this
I'm looking for a more efficient way of completing this task. I need to
I am completing an Android program to classify the genre of a song on
I've created a script where users can get points by completing tasks and then
I am following through this tutorial and after completing it I am getting an
I'm currently completing an assignment that involves using multithreading and multiprocess programming for the
How would I go about completing the following function in vimscript? fun! Foo() let
I'm completing a university assignment in java. It consists of some inputs, a block
Right, I am studying CS and have been completing a lab in C, it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.