Discussions
Categories
- 197K All Categories
- 2.5K Data
- 546 Big Data Appliance
- 1.9K Data Science
- 450.8K Databases
- 221.9K General Database Discussions
- 3.8K Java and JavaScript in the Database
- 31 Multilingual Engine
- 552 MySQL Community Space
- 479 NoSQL Database
- 7.9K Oracle Database Express Edition (XE)
- 3.1K ORDS, SODA & JSON in the Database
- 556 SQLcl
- 4K SQL Developer Data Modeler
- 187.2K SQL & PL/SQL
- 21.4K SQL Developer
- 296.4K Development
- 17 Developer Projects
- 139 Programming Languages
- 293.1K Development Tools
- 110 DevOps
- 3.1K QA/Testing
- 646.1K Java
- 28 Java Learning Subscription
- 37K Database Connectivity
- 161 Java Community Process
- 105 Java 25
- 22.1K Java APIs
- 138.2K Java Development Tools
- 165.3K Java EE (Java Enterprise Edition)
- 19 Java Essentials
- 162 Java 8 Questions
- 86K Java Programming
- 81 Java Puzzle Ball
- 65.1K New To Java
- 1.7K Training / Learning / Certification
- 13.8K Java HotSpot Virtual Machine
- 94.3K Java SE
- 13.8K Java Security
- 205 Java User Groups
- 24 JavaScript - Nashorn
- Programs
- 475 LiveLabs
- 39 Workshops
- 10.2K Software
- 6.7K Berkeley DB Family
- 3.5K JHeadstart
- 5.7K Other Languages
- 2.3K Chinese
- 175 Deutsche Oracle Community
- 1.1K Español
- 1.9K Japanese
- 233 Portuguese
List Box programs not running

Hi,
i am trying to create List Box. I have tried different programs downloaded from internet but i am getting Xlint:unchecked warning.
G:\Zulfi\java prog\2015\gui\ListBox>javac ListBox1.java
Note: ListBox1.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
G:\Zulfi\java prog\2015\gui\ListBox>javac -Xlint:unchecked ListBox1.java
ListBox1.java:17: warning: [unchecked] unchecked call to JList(E[]) as a member
of the raw type JList
JList list = new JList(options);
^
where E is a type-variable:
E extends Object declared in class JList
1 warning
G:\Zulfi\java prog\2015\gui\ListBox>javac ListBox1.java
Note: ListBox1.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
G:\Zulfi\java prog\2015\gui\ListBox>type ListBox1.java
import java.awt.*;
import javax.swing.*;
public class ListBox1 extends Object{
public static void main(String[] args) {
JFrame frame = new JFrame("Test Frame");
frame.setSize(new Dimension(300,200));
frame.setLocation(100,100);
Container contentPane = frame.getContentPane();
JLabel label = new JLabel("HERE IS A LABEL");
contentPane.add(label, BorderLayout.NORTH);
JButton button = new JButton("BUTTON");
contentPane.add(button, BorderLayout.SOUTH);
String[] options = {"Option 1", "Option 2",
"Option 3"};
JList list = new JList(options);
contentPane.add(list, BorderLayout.CENTER);
frame.setVisible(true);
}
}
However, i have tried and the program is running. Some body please guide me.
Zulfi.
Answers
-
i am trying to create List Box. I have tried different programs downloaded from internet but i am getting Xlint:unchecked warning. G:\Zulfi\java prog\2015\gui\ListBox>javac ListBox1.java Note: ListBox1.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details. G:\Zulfi\java prog\2015\gui\ListBox>javac -Xlint:unchecked ListBox1.java ListBox1.java:17: warning: [unchecked] unchecked call to JList(E[]) as a member of the raw type JList JList list = new JList(options); ^ where E is a type-variable: E extends Object declared in class JList 1 warning
That is a WARNING for the reason given in the exception. You are using a GENERIC class without declaring what TYPE of objects the JList should contain.
See the Java API
Class JList<E>
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.JList<E>
- Type Parameters:
E
- the type of the elements of this list
- All Implemented Interfaces:
- ImageObserver, MenuContainer, Serializable, Accessible, Scrollable
public class JList<E> extends JComponent implements Scrollable, Accessible
See that class declaration? See that 'JList<E>' in it? See the description of the Type Parameter above.
E - the type of the elements of this list
You did NOT tell the compiler what class E is; that is, what type of objects are ALLOWED in the JList. Is this a list of Container? JLabel? JButton? JFrame? String? Integer? What?
You passed a parameter named 'options' that is a String array but you could put ANYTHING in that list since it is just a list of Object types.
JList<String> JList<JButton>
That first declaration tells the compiler this is a list of strings and there should be NOTHING but instances of the String class in it.
The second one declares a list of buttons.
Now the compiler can check that your code doesn't try to put other objects in that list. Try to put a string in the button list and the compiler will give you an ERROR, not a warning.
However, i have tried and the program is running. Some body please guide me.
Correct - that is a 'warning' not an error to remind you that code could possibly put any other kind of object in that list.
If you don't want to see those warnings then do what the exception says and recompile with '-Xlint'.