This discussion is archived
9 Replies Latest reply: May 17, 2013 10:59 AM by aksarben RSS

unable to build project

a.stoyanov Newbie
Currently Being Moderated
Hi all,
I'm using Netbeans IDE 7.3. When i tried to clean and build my project i received the following error:
Note: D:\work\netbeans\snejana_bah\src\myFinance\Categories.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
This class worked fine yesterday and no changes made... Any ideas?

Here is the source:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package myFinance;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;

/**
 *
 * @author Sasho
 */
public class Categories {

//    String host = "jdbc:derby:D:\\sasho\\java_work\\work\\SnejanaBah\\snejana_bah;create=true";
    String host = "jdbc:derby:release\\snejana_bah";
    String uName = "fester";
    String uPass = "fester";
    ResultSet res = null;
    String month = null;
    final DefaultComboBoxModel<DefaultComboBoxModel> model = new DefaultComboBoxModel<DefaultComboBoxModel>(); 
    String[] comboBoxArray;
    Double limit = 0.0;
    String index;
    
    public String getMonth(Integer mon) {

        switch (mon) {
            case 0:
                month = "Януари";
                break;
            case 1:
                month = "Февруари";
                break;
            case 2:
                month = "Март";
                break;
            case 3:
                month = "Април";
                break;
            case 4:
                month = "Май";
                break;
            case 5:
                month = "Юни";
                break;
            case 6:
                month = "Юли";
                break;
            case 7:
                month = "Август";
                break;
            case 8:
                month = "Септември";
                break;
            case 9:
                month = "Октомври";
                break;
            case 10:
                month = "Ноември";
                break;
            case 11:
                month = "Декември";
                break;


        }


        return month;
    }

    public int getMonthInt(String mon) {
        int montInt = 0;
        switch (mon) {
            case "Януари":
                montInt = 0;
                break;
            case "Февруари":
                montInt = 1;
                break;
            case "Март":
                montInt = 2;
                break;
            case "Април":
                montInt = 3;
                break;
            case "Май":
                montInt = 4;
                break;
            case "Юни":
                montInt = 5;
                break;
            case "Юли":
                montInt = 6;
                break;
            case "Август":
                montInt = 7;
                break;
            case "Септември":
                montInt = 8;
                break;
            case "Октомври":
                montInt = 9;
                break;
            case "Ноември":
                montInt = 10;
                break;
            case "Декември":
                montInt = 11;
                break;


        }


        return montInt;
    }

    public ResultSet getLimits(Integer year, String month, Boolean check) {



        try {

            Connection con = DriverManager.getConnection(host, uName, uPass);
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");

            if (check) {
                PreparedStatement ps = con.prepareStatement("select l.ID, "
                        + "c.CATEGORY_NAME as Категория, "
                        + "l.LIMIT_YEAR as Година,"
                        + " l.\"MONTH\" as Месец, "
                        + "l.\"LIMIT\" as Лимит "
                        + "from FESTER.LIMITS l , "
                        + "fester.CATEGORIES c\n"
                        + "where l.CAT_ID = c.ID "
                        + "and l.limit_year = ? "
                        + "order by c.CATEGORY_NAME, l.\"MONTH\"");


                ps.setInt(1, year);


                res = ps.executeQuery();
            } else {
                PreparedStatement ps = con.prepareStatement("select l.ID, "
                        + "c.CATEGORY_NAME as Категория, "
                        + "l.LIMIT_YEAR as Година,"
                        + " l.\"MONTH\" as Месец, "
                        + "l.\"LIMIT\" as Лимит "
                        + "from FESTER.LIMITS l , "
                        + "fester.CATEGORIES c\n"
                        + "where l.CAT_ID = c.ID "
                        + "and l.limit_year = ? "
                        + "and l.month = ? "
                        + "order by c.CATEGORY_NAME, l.\"MONTH\"");


                ps.setInt(1, year);
                ps.setString(2, month);


                res = ps.executeQuery();
            }

        } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(Reports.class.getName()).log(Level.SEVERE, null, ex);
        }


        return res;
    }

    public void insertLimit(Integer cat_id, Integer year, String month, Double limit) {
        try {

            Connection con = DriverManager.getConnection(host, uName, uPass);
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");


            PreparedStatement stmt = con.prepareStatement("select max(id) + 1 as id from FESTER.LIMITS");

            ResultSet rs = stmt.executeQuery();
            Integer id = null;
            while (rs.next()) {
                id = rs.getInt("ID");
            }

            PreparedStatement ps = con.prepareStatement("insert into FESTER.LIMITS \n"
                    + "values(?,?,?,?,?)");

            ps.setInt(1, id);
            ps.setInt(2, cat_id);
            ps.setInt(3, year);
            ps.setString(4, month);
            ps.setDouble(5, limit);


            ps.executeUpdate();








        } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(Reports.class
                    .getName()).log(Level.SEVERE, null, ex);
        }

    }

    public void updateLimit(Integer id, Integer year, String month, Double limit) {

        try {

            Connection con = DriverManager.getConnection(host, uName, uPass);
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");



            PreparedStatement ps = con.prepareStatement("update fester.limits t "
                    + "set t.limit_year = ?, t.month = ?, t.limit = ? "
                    + "where t.id = ?");

            ps.setInt(1, year);
            ps.setString(2, month);
            ps.setDouble(3, limit);
            ps.setInt(4, id);


            ps.executeUpdate();

        } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(Reports.class
                    .getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void insertCategory(String catName, Integer type, String Desc) {

        try {
            Integer id = 0;

            Connection con = DriverManager.getConnection(host, uName, uPass);
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");

            PreparedStatement st = con.prepareStatement("select max(id) + 1 as id from fester.categories");

            ResultSet rs = st.executeQuery();

            while (rs.next()) {
                id = rs.getInt("ID");
            }

            PreparedStatement ps = con.prepareStatement("insert into fester.categories values(?,?,?,?)");

            ps.setInt(1, id);
            ps.setString(2, catName);
            ps.setString(3, Desc);
            ps.setInt(4, type);



            ps.executeUpdate();

        } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(Reports.class
                    .getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void fillCombobox(JComboBox box) {

        try {


            Connection con = DriverManager.getConnection(host, uName, uPass);
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");


            PreparedStatement ps = con.prepareStatement("select category_name from fester.categories where id <> 0 group by category_name");


            ResultSet rs = ps.executeQuery();


            while (rs.next()) {

                box.addItem(rs.getObject(1));
            }



        } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(Reports.class
                    .getName()).log(Level.SEVERE, null, ex);
        }

    }

    public void fillComboboxDebit(JComboBox box) {

        try {


            Connection con = DriverManager.getConnection(host, uName, uPass);
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");


            PreparedStatement ps = con.prepareStatement("select category_name from fester.categories where id <> 0 "
                    + "and trx_type = 1 "
                    + "group by category_name");


            ResultSet rs = ps.executeQuery();


            while (rs.next()) {

                box.addItem(rs.getObject(1));
            }



        } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(Reports.class
                    .getName()).log(Level.SEVERE, null, ex);
        }

    }

    public void fillComboboxCredit(JComboBox box) {

        try {


            Connection con = DriverManager.getConnection(host, uName, uPass);
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");


            PreparedStatement ps = con.prepareStatement("select category_name from fester.categories where id <> 0 "
                    + "and trx_type = 0 "
                    + "group by category_name");


            ResultSet rs = ps.executeQuery();


            while (rs.next()) {

                box.addItem(rs.getObject(1));
            }



        } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(Reports.class
                    .getName()).log(Level.SEVERE, null, ex);
        }

    }

    public Double getCurrentLimit(Integer catId, String month) {
        try {


            Connection con = DriverManager.getConnection(host, uName, uPass);
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");


            PreparedStatement ps = con.prepareStatement("select limit from fester.limits where cat_id = ? and month = ?");

            ps.setInt(1, catId);
            ps.setString(2, month);
            ResultSet rs = ps.executeQuery();


            while (rs.next()) {
                limit = rs.getDouble("limit");
            }



        } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(Reports.class
                    .getName()).log(Level.SEVERE, null, ex);
        }
        return limit;

    }

    public Double getTotal(int month, Integer year, Integer catId) {
        try {


            Connection con = DriverManager.getConnection(host, uName, uPass);
            Class.forName("org.apache.derby.jdbc.EmbeddedDriver");


            PreparedStatement ps = con.prepareStatement("select sum(t.AMOUNT) as amnt from fester.TRANSACTIONS t \n"
                    + "where month(t.DATE_CREATED) = ?\n"
                    + "and year(t.DATE_CREATED) = ?\n"
                    + "and t.CATEGORY = ?  ");


            ps.setInt(1, month);
            ps.setInt(2, year);
            ps.setInt(3, catId);
            ResultSet rs = ps.executeQuery();


            while (rs.next()) {
                limit = rs.getDouble("amnt");
            }



        } catch (SQLException | ClassNotFoundException ex) {
            Logger.getLogger(Reports.class
                    .getName()).log(Level.SEVERE, null, ex);
        }
        return limit;

    }

    public String getLimitIndex(Double total, Double limit) {



        if (total > limit) {
            index = "Отрицателен";
        } else {
            index = "Положителен";
        }

        return index;

}
Thanks in advance,
Alexander.
  • 1. Re: unable to build project
    gimbal2 Guru
    Currently Being Moderated
    Before making assumptions that border on the supernatural, do as the Java compiler tells you and find out which lines it has problems with. Than you can easily see what is the truth and what is not. Sometimes IDEs go loopy because for example something fudges up when the project settings are saved during shutdown, but you must first make a case where you have the right to believe that.
  • 2. Re: unable to build project
    a.stoyanov Newbie
    Currently Being Moderated
    Hi,
    Thanks for reply. I believe that the error comes from the line:
    final DefaultComboBoxModel<DefaultComboBoxModel> model = new DefaultComboBoxModel<DefaultComboBoxModel>();
    When i comment the methods using this - i'm able to clean and build the project. Maybe something wrong here with the Generics... I cannot find how to apply this
    Recompile with -Xlint:unchecked for details
    Any ideas?


    Thanks,
    Alexander.
  • 3. Re: unable to build project
    Tolls Journeyer
    Currently Being Moderated
    Doesn't Netbeans underline lines with warnings using yellow?
  • 4. Re: unable to build project
    a.stoyanov Newbie
    Currently Being Moderated
    Hi,
    Thanks for reply.
    It does. It's this line:
    final DefaultComboBoxModel<DefaultComboBoxModel> model = new DefaultComboBoxModel<DefaultComboBoxModel>();
    So the hint was to change it to diamond reference and i made it :

    final DefaultComboBoxModel<DefaultComboBoxModel> model = new DefaultComboBoxModel <> ();
    But i still receive the error:
    Note: D:\work\netbeans\snejana_bah\src\myFinance\Categories.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    Ideas?

    Thanks in advance,
    Alexander.

    Edited by: a.stoyanov on May 16, 2013 5:04 AM
  • 5. Re: unable to build project
    a.stoyanov Newbie
    Currently Being Moderated
    Due to this editor i'm unable to add html brackets
    so after diamond reference it looks like : final DefaultComboBoxModel<DefaultComboBoxModel> model = new DefaultComboBoxModel <html brackets> ();

    Edited by: a.stoyanov on May 16, 2013 5:05 AM

    Edited by: a.stoyanov on May 16, 2013 5:05 AM
  • 6. Re: unable to build project
    gimbal2 Guru
    Currently Being Moderated
    Tolls wrote:
    Doesn't Netbeans underline lines with warnings using yellow?
    It does, unless you turn it off.
    DefaultComboBoxModel<DefaultComboBoxModel>
    Quite odd to see the class itself in the generic type definition.


    Also get the terminology straight: you are not getting errors, you are getting warnings.
  • 7. Re: unable to build project
    a.stoyanov Newbie
    Currently Being Moderated
    So... the class can be build with this warning and if i run the project from the IDE it's working fine... But if i start the jar file from the DIST folder - it doesn't. The methods from this class are not used.
    The purpose of this class is to fill comboboxes and i refer to it in the init components. So, when the project is being started - the comboboxes are empty...
  • 8. Re: unable to build project
    a.stoyanov Newbie
    Currently Being Moderated
    I checked the -Xlint:unchecked option in my IDE
    and here is the warning message:
    D:\work\netbeans\snejana_bah\src\myFinance\Categories.java:301: warning: [unchecked] unchecked call to addItem(E) as a member of the raw type JComboBox
                    box.addItem(rs.getObject(1));
      where E is a type-variable:
        E extends Object declared in class JComboBox
    D:\work\netbeans\snejana_bah\src\myFinance\Categories.java:335: warning: [unchecked] unchecked call to addItem(E) as a member of the raw type JComboBox
                    box.addItem(rs.getObject(1));
      where E is a type-variable:
        E extends Object declared in class JComboBox
    D:\work\netbeans\snejana_bah\src\myFinance\Categories.java:366: warning: [unchecked] unchecked call to addItem(E) as a member of the raw type JComboBox
                    box.addItem(rs.getObject(1));
      where E is a type-variable:
        E extends Object declared in class JComboBox
    3 warnings
    Alexander.
  • 9. Re: unable to build project
    aksarben Journeyer
    Currently Being Moderated
    This borders on being outside my area of expertise, but why do you have new X<X>() instead of new X() ? This seems an exceedingly odd design and might be confusing the compiler. Perhaps a redesign is in order?

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points