hello all
my part of code give me message to recompile with -Xlint:unchecked
How to fix this code so the message gone

thank you


FileRead fr=new FileRead();
String astring=fr.Read(filePath);
/* delimiter */
String delimiter = ",";
/* given string will be split by the argument delimiter provided. */
String[] temp = astring.split(delimiter);
comboCity=new JComboBox(temp);
comboCity=new JComboBox();

The compiler sould be giving you a specific exception to catch or a specific object that needs its creation checked, right?

Have you added that option for the compiler and compiled the code to have the compiler show you the statement that is causing the warning?

hello Thines01 and NormRI and all

I mean how to fix my code, so that the message not appear when I compile
without using option "-Xlint:unchecked"
Right now the code work fine,but I have to add the option when compile.
I attach below the compile command line when I compile with and without the option


C:\LJava\project\KwitansiJ>javac -Xlint:unchecked -d build -cp .;.\build .\src\K
.\src\KwitansiJava07.java:257: warning: [unchecked] unchecked call to JComboBox(
E[]) as a member of the raw type JComboBox
comboKota=new JComboBox(kota2);
where E is a type-variable:
E extends Object declared in class JComboBox
1 warning

C:\LJava\project\KwitansiJ>javac -d build -cp .;.\build .\src\KwitansiJava07.jav
Note: .\src\KwitansiJava07.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

comboKota=new JComboBox(kota2);

What is kota2? Your posted code has temp there.

hello NormRI
kota2 is String[];
yes I replace the word temp with kota2 but they are the same aka String[]
it's content are name of cities;

thank you

my part of code give me message to recompile with -Xlint:unchecked
How to fix this code so the message gone

JComboBox was made a generic type in Java 7 so creating a new JComboBox without supplying the type parameters would result in the usual "unsafe" warning. The solution here would be to specify the type parameter when creating the combo box, something like:

import javax.swing.*;
public class Test {

    public static void main(final String[] args) {
        final String[] strs = { "a", "b", "c" };
        final JComboBox<String> cbox = new JComboBox<>(strs);

commented: Object not String +10

hi ~s.o.s~

I use text file as String[] source ,so String[] member can be added or edited easily.
For example String[] cities is got by split from String "London,New york,Tokyo,Beijing,Paris"
Using your example make I only be able to add or edit through code.
I think it no good for the code user.

thank you

I posted a sample code. My point was that you just need to make sure you are passing a type parameter when creating JComboBox and you should be good to go. Something like:

JComboBox<String> comboCity = new JComboBox<>(temp);

hello ~s.o.s~
it works

thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.