Busy with a school project, and NetBeans is frustrating me to death. Please help me resolve the below error and please show me what I have done wrong.
I'm busy with bindings and Apache Derby. What I'm doing is I'm binding data from the database to text fields. I have a JFrame Form with two tabbed panels. One has a table on it 1, and another one shows individual records 2.
This is an extract of the coding for the binding on the single record view:
1 package UserManager;
import java.util.*;
5 /**
*
* @author Johan Brink
*/
public class Data extends javax.swing.JFrame {
10 Users users = new Users();
ListIterator<Users>iterator;
public Users getUsers() {
return users;
15 }
public void setUsers(Users users) {
Users oldUsers = this.users;
this.users = users;
20 firePropertyChange("users", oldUsers, users);
}
/**
* Creates new form Data
25 */
public Data() {
initComponents();
setLocationRelativeTo(rootPane);
iterator = usersList.listIterator(0);
30 setUsers(iterator.next());
}
The problem lies on lines 29 and 30. This have worked in the past, but now I get an error. I have an automatically-created entity class, etc. Without lines 29 and 30, everything works except the individual records information isn't listed. When lines 29 and 30 is inserted, the following error is displayed when run:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: Cannot cast java.util.Date to java.lang.String
at java.lang.Class.cast(Class.java:3084)
at org.jdesktop.beansbinding.Binding.convertForward(Binding.java:1312)
at org.jdesktop.beansbinding.Binding.getSourceValueForTarget(Binding.java:844)
at org.jdesktop.beansbinding.Binding.refreshUnmanaged(Binding.java:1222)
at org.jdesktop.beansbinding.Binding.refresh(Binding.java:1207)
at org.jdesktop.beansbinding.AutoBinding.tryRefreshThenSave(AutoBinding.java:162)
at org.jdesktop.beansbinding.AutoBinding.sourceChangedImpl(AutoBinding.java:227)
at org.jdesktop.beansbinding.Binding.sourceChanged(Binding.java:1411)
at org.jdesktop.beansbinding.Binding.access$1200(Binding.java:38)
at org.jdesktop.beansbinding.Binding$PSL.propertyStateChanged(Binding.java:1618)
at org.jdesktop.beansbinding.PropertyHelper.firePropertyStateChange(PropertyHelper.java:212)
at org.jdesktop.beansbinding.ELProperty.notifyListeners(ELProperty.java:688)
at org.jdesktop.beansbinding.ELProperty.access$800(ELProperty.java:155)
at org.jdesktop.beansbinding.ELProperty$SourceEntry.processSourceChanged(ELProperty.java:312)
at org.jdesktop.beansbinding.ELProperty$SourceEntry.sourceChanged(ELProperty.java:326)
at org.jdesktop.beansbinding.ELProperty$SourceEntry.propertyChange(ELProperty.java:333)
at java.beans.PropertyChangeSupport.fire(PropertyChangeSupport.java:335)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:327)
at java.beans.PropertyChangeSupport.firePropertyChange(PropertyChangeSupport.java:263)
at java.awt.Component.firePropertyChange(Component.java:8382)
at UserManager.Data.setUsers(Data.java:24)
at UserManager.Data.<init>(Data.java:34)
at UserManager.Data$7.run(Data.java:419)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:733)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:694)
at java.awt.EventQueue$3.run(EventQueue.java:692)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:703)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:146)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:138)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:91)
You have not included the code that is the root problem, but the exception says that the binding code is attempting to cast a String
to a Date
... and that's a big no-no in Java!
I suspect the problem is that you have a date-of-birth field in the User
object that has type Date
and the binding object is attempting to reflectively assign a String
to it.
If this is the problem, then you need to add a custom Converter
to the relevant Binding
object to convert between String
and Date
objects. It looks like you will need to write a custom converter to do the job.
References: