Exception (payword protocol)
Code :
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: -1
at java.util.ArrayList.get(ArrayList.java:323)
at payword.user.CertificateTableModel.getSelected(CertificateTableModel.java:61)
at payword.user.ClientWindow.vendorConnectButtonActionPerformed(ClientWindow.java:373)
at payword.user.ClientWindow.access$500(ClientWindow.java:23)
at payword.user.ClientWindow$6.actionPerformed(ClientWindow.java:182)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236)
at java.awt.Component.processMouseEvent(Component.java:5517)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3135)
at java.awt.Component.processEvent(Component.java:5282)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3984)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3819)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1791)
at java.awt.Component.dispatchEvent(Component.java:3819)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
any idea for this exception???
http://img24.imageshack.us/img24/6669/runfile.jpg
This exception appears when i push "Connect" button for ports : 11201 (client-vendor connection) and 11202 (vendor-broker connection).
The database is created by WampServer application..
Re: Exception (payword protocol)
Without code posted we all have to rely on guesses. Here's my guess: you are accessing an ArrayList for index -1, which will throw an exception. Based upon the stack trace, I'd guess you are trying to get the selected row or column within a table - but there are none selected so the returned selected row is -1 (JTable (Java 2 Platform SE 5.0)). Again beyond that its anyone's guess...
Re: Exception (payword protocol)
Quote:
Originally Posted by
copeg
Without code posted we all have to rely on guesses. Here's my guess: you are accessing an ArrayList for index -1, which will throw an exception. Based upon the stack trace, I'd guess you are trying to get the selected row or column within a table - but there are none selected so the returned selected row is -1 (
JTable (Java 2 Platform SE 5.0)). Again beyond that its anyone's guess...
Client to Vendor Connection
Code :
package payword.user;
import payword.User;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import payword.ClientCommitment;
/**
*
* @author Thodoris
*/
public class ClientToVendorConnection {
private Socket socket;
private String address;
private int port;
private ClientWindow parent;
private ClientCommitment commitment;
private User user;
public ClientToVendorConnection(String address, int port, ClientWindow parent, ClientCommitment commitment, User user) {
this.address = address;
this.port = port;
this.parent = parent;
this.commitment = commitment;
this.user = user;
connect();
}
public void connect(){
Thread t = new Thread(new Runnable() {
public void run() {
try {
socket = new Socket(address, port);
parent.log("Connected to: " + address + ":" + port);
// Στέλνω το commitment για να γράψει ο vendor τα στοιχεία του
ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
out.writeObject(commitment);
out.flush();
// Παίρνω πίσω το commitment μαζί με τα στοιχεία του vendor και υπολογίζω την υπογραφή και το paychain
ObjectInputStream iin = new ObjectInputStream(socket.getInputStream());
commitment = (ClientCommitment)iin.readObject();
commitment.calculatePayChain(user.getUserPrivateKey());
commitment.setWRoot(null);
// Στέλνω στον έμπορο το τελικό commitment.
out.writeObject(commitment);
parent.log("User commitment sent.");
socket.close();
} catch (Exception ex) {
parent.log("ERROR: " + ex.getMessage());
}
}
});
t.run();
}
}
Vendor to Client connection
Code :
package payword.vendor;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
import payword.ClientCommitment;
/**
*
* @author Thodoris
*/
public class VendorToClientConnection {
private VendorWindow parent;
private ServerSocket serverSocket;
private ClientCommitment commitment;
private int port;
public VendorToClientConnection(int port, VendorWindow parent, ClientCommitment commitment) {
this.parent = parent;
this.commitment = commitment;
this.port = port;
}
public void startListening(){
Thread thread = new Thread(new Runnable() {
public void run() {
try {
serverSocket = new ServerSocket(port);
parent.log("VendorToClient: Start listening port " + port);
} catch (IOException ex) {
parent.log("ERROR: Could not start listening port: " + port);
}
try {
Socket socket = serverSocket.accept();
parent.log("Accepted connection.");
// Παίρνω το commitment και γράφω το vendorInfo
ObjectInputStream iin = new ObjectInputStream(socket.getInputStream());
ClientCommitment commitment = (ClientCommitment)iin.readObject();
parent.log("Commitment received.");
commitment.setVendorInfo("Vendor One");
// Στέλνω πίσω το commitment για να μπορέσει ο client να υπολογίσει το wRoot
ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
out.writeObject(commitment);
parent.log("Sent.");
commitment = (ClientCommitment)iin.readObject();
parent.log("Final commitment received.");
parent.log("vendorInfo: " + commitment.getVendorInfo());
parent.log("userInfo: " + commitment.getCertificate().getUserName());
parent.log("ammount: " + commitment.getAmmount());
parent.log("Vendor: Commitment received.");
VendorDbConnection con = new VendorDbConnection();
con.saveCommitment(commitment);
socket.close();
} catch (Exception ex) {
Logger.getLogger(VendorToClientConnection.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
thread.start();
}
public void disconnect(){
try {
serverSocket.close();
} catch (IOException ex) {
parent.log("ERROR: Could not disconnect.");
}
}
}
And this is the Certificate Table Model .. that comes the error
Code :
package payword.user;
import payword.User;
import java.util.ArrayList;
import java.util.List;
import javax.swing.table.AbstractTableModel;
import payword.ClientCertificate;
/**
*
* @author Thodoris
*/
public class CertificateTableModel extends AbstractTableModel {
int lines = 0;
List<ClientCertificate> contents = new ArrayList<ClientCertificate>();
public void refreshTable(User user){
ClientDbConnection connection = new ClientDbConnection();
contents = connection.getCertificateList(user);
lines = contents.size();
fireTableDataChanged();
connection.close();
}
public int getRowCount() {
return lines;
}
public int getColumnCount() {
return 3;
}
public Object getValueAt(int rowIndex, int columnIndex) {
ClientCertificate cert = contents.get(rowIndex);
if(columnIndex == 0){
return cert.getUserName();
}else if(columnIndex == 1){
return cert.getExpirationDate();
}else{
return cert.getAmmount();
}
}
@Override
public String getColumnName(int column){
if(column == 0){
return "Broker";
}else if(column==1){
return "Expires";
}else{
return "Ammount";
}
}
public ClientCertificate getSelected(int i){
return contents.get(i);
}
}
Re: Exception (payword protocol)
The exception is being thrown in the ClientWindow vendorConnectButtonActionPerformed() method, please post that code.
Re: Exception (payword protocol)
here you are..
Code :
private void vendorConnectButtonActionPerformed(java.awt.event.ActionEvent evt) {
int port = Integer.parseInt(portTf1.getText());
int amount = (Integer)amountSpinner.getValue();
int i = certificateTable.getSelectedRow();
CertificateTableModel model = (CertificateTableModel)certificateTable.getModel();
ClientCommitment commitment = new ClientCommitment(model.getSelected(i), new Date(), "", amount);
vendorConnection = new ClientToVendorConnection(addressTf1.getText(), port, this, commitment, user);
Re: Exception (payword protocol)
And here I thought you may have actually taken my first suggestion...Read the API for getSelectedRow() JTable (Java 2 Platform SE 5.0)
Code :
int i = certificateTable.getSelectedRow();
i will be -1 if there are no rows selected, and you cannot access an ArrayList index at -1 in the following line of code
Code :
model.getSelected(-1) ///will throw an exception
Fix is to make sure i is within the bounds of your list
Re: Exception (payword protocol)
ill give it a try
tnx for your help copeg!