简体   繁体   English

我似乎无法修复的Netbeans错误

[英]Netbeans Error I cant seem to fix

Im a rookie programmer working on a project that involves MySQL, Netbeans and Wamp. 我是一个新手程序员,从事涉及MySQL,Netbeans和Wamp的项目。 Im trying to link certain rows entered into a GUI to my database, but it is consistently throwing errors our way. 我试图将输入GUI的某些行链接到我的数据库,但是它一直在向我们抛出错误。 The teacher even went through the code to find a solution to no avail, so I'd like to ask some of you to see if you could help me spot the error. 老师甚至遍历了代码,以找到无济于事的解决方案,所以我想请你们中的一些人看看您是否可以帮助我发现错误。 The code is as follows: 代码如下:

private void btn_processOrderActionPerformed(java.awt.event.ActionEvent evt) {                                                 
    // TODO add your handling code here:
    if(     check_addressNew.isSelected()==true) { 
    Shipping add = new Shipping();
    add.setAddress1(txt_deliveryAddress1.getText());
    add.setAddress2(txt_deliveryAddress2.getText());
    add.getState(txt_deliveryState.getText());
    add.setSuburb (txt_deliverySuburb.getText());
    add.setPostcode (txt_deliveryPostcode.getText());  

    ModernGlassConnection myConnection = new ModernGlassConnection();
    myConnection.setShipping(add);


}                                                

}

Following is the Setters and Getters 以下是Setters和Getters

  package Modern_Glass;

/**
 *
 * @author 
 */
public class Shipping {
        private String address1; 
        private String address2;
        private String states;
        private String suburb;
        private String postcode; 

    /**
     * @return the address1
     */
    public String getAddress1() {
        return address1;
    }

    /**
     * @param address1 the address1 to set
     */
    public void setAddress1(String address1) {
        this.address1 = address1;
    }

    /**
     * @return the address2
     */
    public String getAddress2() {
        return address2;
    }

    /**
     * @param address2 the address2 to set
     */
    public void setAddress2(String address2) {
        this.address2 = address2;
    }

    /**
     * @return the state
     */
    public String getState() {
        return states;
    }

    /**
     * @param state the state to set
     */
    public void setState(String state) {
        this.states = state;
    }

    /**
     * @return the suburb
     */
    public String getSuburb() {
        return suburb;
    }

    /**
     * @param suburb the suburb to set
     */
    public void setSuburb(String suburb) {
        this.suburb = suburb;
    }

    /**
     * @return the postcode
     */
    public String getPostcode() {
        return postcode;
    }

    /**
     * @param postcode the postcode to set
     */
    public void setPostcode(String postcode) {
        this.postcode = postcode;
    }

    void getState(String text) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }



}

And then the connection code 然后是连接代码

package Modern_Glass;

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;

public class ModernGlassConnection {
    // ****** START DATABASE CONNECTION ****** //
    public Connection connection = null;
    public Connection getConnection() {
        try {
            System.out.println("---------MySQL Connection Testing---------");
            Class.forName("com.mysql.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            System.out.println("Can't find MySQL Driver");
            return null;
//            e.printStackTrace();
        }

        System.out.println("My Driver Registered");

        try {
            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/modernglass","root","");
            return connection;
        } catch  (SQLException e) {
            System.out.println("Connection fail!!!");
        }

        if (connection != null) {
            System.out.println("Connection Success!!!");
        } else {
            System.out.println("Connection fail - check your database server!!!");
        }

        return connection ;
    } // ****** END DAT ABASE CONNECTION ****** //

   public void setShipping(Shipping address) {

        String insertDate = 
        "INSERT INTO Orders (deliveryAddress1, deliveryAddress2, deliveryState, deliverySuburb, deliveryPostcode) " +
        "VALUES ( ? , ? , ? , ? , ? )";



       Connection connection = getConnection();
       System.out.println("Connection established");
        try {
            PreparedStatement ps = connection.prepareStatement(insertDate);
            String ad1 = address.getAddress1();
        String ad2 = address.getAddress2();
        String ad3 = address.getState();
        String ad4 = address.getSuburb();
        String ad5 = address.getPostcode();

            ps.setString(1, address.getAddress1());
            ps.setString(2, address.getAddress2());
            ps.setString(3, address.getState());
            ps.setString(4, address.getSuburb());
           // int postcode = Integer.parseInt(address.getPostcode());
            //ps.setString(5,address.getPostcode()  );
           int rs = ps.executeUpdate();
        } catch (SQLException ex) {
            Logger.getLogger(ModernGlassConnection.class.getName()).log(Level.SEVERE, null, ex);
        }
    }                                               
   }

The error that it spits out is : 它吐出的错误是:

Exception in thread "AWT-EventQueue-0" java.lang.UnsupportedOperationException: Not supported yet.
    at Modern_Glass.Shipping.getState(Shipping.java:91)
    at Modern_Glass.Modern_Glass_GUI_Delivery_Details.btn_processOrderActionPerformed(Modern_Glass_GUI_Delivery_Details.java:218)
    at Modern_Glass.Modern_Glass_GUI_Delivery_Details.access$200(Modern_Glass_GUI_Delivery_Details.java:13)
    at Modern_Glass.Modern_Glass_GUI_Delivery_Details$3.actionPerformed(Modern_Glass_GUI_Delivery_Details.java:127)
    at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
    at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2346)
    at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
    at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:252)
    at java.awt.Component.processMouseEvent(Component.java:6527)
    at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
    at java.awt.Component.processEvent(Component.java:6292)
    at java.awt.Container.processEvent(Container.java:2234)
    at java.awt.Component.dispatchEventImpl(Component.java:4883)
    at java.awt.Container.dispatchEventImpl(Container.java:2292)
    at java.awt.Component.dispatchEvent(Component.java:4705)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4898)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4533)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4462)
    at java.awt.Container.dispatchEventImpl(Container.java:2278)
    at java.awt.Window.dispatchEventImpl(Window.java:2739)
    at java.awt.Component.dispatchEvent(Component.java:4705)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:746)
    at java.awt.EventQueue.access$400(EventQueue.java:97)
    at java.awt.EventQueue$3.run(EventQueue.java:697)
    at java.awt.EventQueue$3.run(EventQueue.java:691)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:86)
    at java.awt.EventQueue$4.run(EventQueue.java:719)
    at java.awt.EventQueue$4.run(EventQueue.java:717)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:75)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:716)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:201)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:116)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:105)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:82)

Thank you in advance - 先感谢您 -

private void btn_processOrderActionPerformed(java.awt.event.ActionEvent evt)

calls 来电

add.getState(txt_deliveryState.getText());

which executes 执行

throw new UnsupportedOperationException("Not supported yet.");

which is excactly the exception that is thrown. 恰恰是抛出的异常。 (second line in the stack trace should be exactly that line) (堆栈跟踪中的第二行应该正是该行)

I think it's that 我想就是

add.getState(txt_deliveryState.getText());

should be changed to 应该更改为

add.setState(txt_deliveryState.getText());

and the getter wasn't meant to have an partameter, i guess. 我想,吸气剂并不意味着具有比色计。

BTW: You can get that info from the stack trace. 顺便说一句:您可以从堆栈跟踪中获取该信息。 Just take a look at the first line, that is from one of your classes. 只需看看第一行,那是您的一个类。 This helps in most situations. 这在大多数情况下都有帮助。 Netbeans should even create a link out of the code line. Netbeans甚至应该在代码行之外创建一个链接。 ( (Shipping.java:91) in this case). (在这种情况下为(Shipping.java:91) )。 Just click on that link and NetBeans should jump right to that line. 只需单击该链接,NetBeans应该跳到该行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM