Cannot find TopComponent with preferredID - java

I'm trying to run my simple java-program, but have a big problem.
It's connected with GUI. It can not show any created window. I attach stack-trace and one class.
#ConvertAsProperties(
dtd = "-//org.shop.viewer//ShopViewer//EN",
autostore = false
)
#TopComponent.Description(
preferredID = "ShopViewerTopComponent",
//iconBase="SET/PATH/TO/ICON/HERE",
persistenceType = TopComponent.PERSISTENCE_ALWAYS
)
#TopComponent.Registration(mode = "explorer", openAtStartup = false)
#ActionID(category = "Window", id = "org.shop.viewer.ShopViewerTopComponent")
#ActionReference(path = "Menu/Window" /*, position = 333 */)
#TopComponent.OpenActionRegistration(
displayName = "#CTL_ShopViewerAction",
preferredID = "ShopViewerTopComponent"
)
#Messages({
"CTL_ShopViewerAction=ShopViewer",
"CTL_ShopViewerTopComponent=ShopViewer Window",
"HINT_ShopViewerTopComponent=This is a ShopViewer window"
})
public final class ShopViewerTopComponent extends TopComponent {
public ShopViewerTopComponent() {
initComponents();
setName(Bundle.CTL_ShopViewerTopComponent());
setToolTipText(Bundle.HINT_ShopViewerTopComponent());
EntityManager entityManager = Persistence.createEntityManagerFactory("ShopLibraryPU").createEntityManager();
Query query = entityManager.createNamedQuery("Shops.findAll");
List<Shops> resultList = query.getResultList();
for (Shops c : resultList) {
jTextArea1.append(c.getTitle() +"dqwdqwdqwdqwd"+ "\n");
}
}
java.lang.IllegalStateException: Cannot find TopComponent with preferredID ShopViewerTopComponent, see IDE log for more details.
at org.openide.windows.OpenComponentAction.actionPerformed(OpenComponentAction.java:91)
at org.openide.awt.AlwaysEnabledAction$1.run(AlwaysEnabledAction.java:198)
at org.openide.util.actions.ActionInvoker$1.run(ActionInvoker.java:95)
at org.openide.util.actions.ActionInvoker.doPerformAction(ActionInvoker.java:116)
at org.openide.util.actions.ActionInvoker.invokeAction(ActionInvoker.java:99)
at org.openide.awt.AlwaysEnabledAction.actionPerformed(AlwaysEnabledAction.java:201)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:402)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:259)
at javax.swing.AbstractButton.doClick(AbstractButton.java:376)
at javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:833)
at javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:877)
at java.awt.Component.processMouseEvent(Component.java:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
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.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at org.netbeans.core.TimableEventQueue.dispatchEvent(TimableEventQueue.java:159)
[catch] 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)
I think that a misstake is in TopComponent-constructor.
Thanks a lot.

This problem "cannot find TopCoponent with preferredID..." happens frequently when a problem occurs before loading the TopComponent.
A simple example : you try to load something in the constructor that fails (at any depth).
This unexplicit message made me mad more than once !
Hope this helps.

Related

Adding FeatureCollection to a FeatureStore throwing AbstractMethodError

This method is supposed to replace the features in the database with new features I pass to it.
private static void replaceBoundaryShape(FeatureCollection<SimpleFeatureType, SimpleFeature> dbFeatures) throws IOException, CQLException{
FeatureStore<SimpleFeatureType, SimpleFeature> fs = null;
FeatureSchemaFactory factory = FeatureSchemaFactory.init();
DataStore geoStore = initDataStore();
try{
fs = (FeatureStore) geoStore.getFeatureSource(factory.getFieldFeatureSchema().getTypeName());
fs.setTransaction(new DefaultTransaction());
for(FeatureIterator<SimpleFeature> iterator = dbFeatures.features(); iterator.hasNext();){
SimpleFeature simpleFeature = iterator.next();
Number fieldId = (Number) simpleFeature.getAttribute(FeatureSchemaFactory.FIELD_ID);
Filter filter = createSearchByIdFilter(fieldId.longValue());
fs.removeFeatures(filter);
}
fs.addFeatures(dbFeatures);
fs.getTransaction().commit();
}catch(CQLException ex){
throw new CQLException(ex.getMessage());
}
}
this is where I create the feature collection passed to replace boundary shape
private static FeatureCollection<SimpleFeatureType, SimpleFeature> createBoundaryFeatures(SimpleFeatureType dbSchema, Collection<FieldFeature> fields){
List<SimpleFeature> result = new ArrayList<SimpleFeature>(fields.size());
SimpleFeatureBuilder builder = new SimpleFeatureBuilder(dbSchema);
for(FieldFeature f: fields){
builder.set("BNDRS", f.getGeometries());
builder.set("FIELD", f.getField());
builder.set("FID", f.getFid());
builder.set("GROWER", f.getGrower());
builder.set("SIMPLIFIED_BNDRS", f.getSimplifiedGeometries());
result.add(builder.buildFeature(null));
}
return DataUtilities.collection(result);
}
This is where I get my field features from a file path and a specified field:
private static Collection<FieldFeature> convertShpFile(String filePath, Field field) throws MalformedURLException, IOException{
#SuppressWarnings("deprecation")
ShapefileDataStore source = new ShapefileDataStore(new File(filePath).toURL());
Collection<FieldFeature> result = new LinkedList<FieldFeature>();
DefaultQuery query = new DefaultQuery();
query.setCoordinateSystemReproject(DefaultGeographicCRS.WGS84);
FeatureCollection queryResult = source.getFeatureSource().getFeatures(query);
FeatureIterator<SimpleFeature> fi = queryResult.features();
while(fi.hasNext()){
SimpleFeature feature = fi.next();
FieldFeature fieldFeature = new FieldFeature();
Object defaultGeometry = feature.getDefaultGeometry();
if(defaultGeometry instanceof Polygon){
Polygon polygon = (Polygon) defaultGeometry;
Polygon[] polygons = {polygon};
defaultGeometry = geometryFactory.createMultiPolygon(polygons);
}
fieldFeature.setField(field.getId());
fieldFeature.setGeometries(defaultGeometry);
fieldFeature.setSimplifiedGeometries(GeoHelper.simplifyGeometry((Geometry) defaultGeometry));
result.add(fieldFeature);
}
fi.close();
source.dispose();
return result;
}
The error occurs on the fs.addFeatures(dbFeatures) line of the replaceBoundaryShape method.
Removing features does not throw an error, but when I call the addFeatures function I receive this AbstractMethodError:
java.lang.AbstractMethodError: org.geotools.jdbc.PreparedStatementSQLDialect.setGeometryValue(Lcom/vividsolutions/jts/geom/Geometry;IILjava/lang/Class;Ljava/sql/PreparedStatement;I)V
The error appears to be thrown when the features are being inserted into the JDBCDataStore
EDIT: Here is the full stack trace
java.lang.AbstractMethodError: org.geotools.jdbc.PreparedStatementSQLDialect.setGeometryValue(Lcom/vividsolutions/jts/geom/Geometry;IILjava/lang/Class;Ljava/sql/PreparedStatement;I)V
at org.geotools.jdbc.JDBCDataStore.insertSQLPS(JDBCDataStore.java:4005)
at org.geotools.jdbc.JDBCDataStore.insert(JDBCDataStore.java:1582)
at org.geotools.jdbc.JDBCDataStore.insert(JDBCDataStore.java:1545)
at org.geotools.jdbc.JDBCInsertFeatureWriter.write(JDBCInsertFeatureWriter.java:76)
at org.geotools.data.InProcessLockingManager$1.write(InProcessLockingManager.java:337)
at org.geotools.data.store.ContentFeatureStore.addFeature(ContentFeatureStore.java:309)
at org.geotools.data.store.ContentFeatureStore.addFeatures(ContentFeatureStore.java:263)
at com.conserviscorp.shape.upload.FieldDAO.replaceBoundaryShape(FieldDAO.java:146)
at com.conserviscorp.shape.upload.FieldDAO.updateFieldData(FieldDAO.java:116)
at com.conserviscorp.ui.MatchedFieldFrame$2.actionPerformed(MatchedFieldFrame.java:83)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
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:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
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.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
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)
The issue was that I was using the wrong version of geotools. When adding items to the dependencies I was using the 10-beta version in some parts, and the current version in other parts.

Null Pointer Error Swing and Database

Below is the code, Spent Hour trying to track where is error...
Code is much big... more then 45 Fields so more confused
Exception is `java.lang.NullPointerException`
code is
String Scholno=getScholarNo();
ScholarNo.setText(Scholno);
addstudent = cnn.prepareStatement ("Insert into student(
ScholarNo, Student_Name, Application_No, DateOfAdmission,
Fathers_Name, Gender, DOB, Address, Session, Contact_no, Email, Course,
Branch, Submitted_Documents, Nationality, GuardianName, GuardianContactNo,
GuardianAddress, High_School_name, HS_Year_of_passing, HS_Percentage,
HS_Board, Higher_secondary_Name, H_year_of_passing, H_percentage,
H_board, Graduation, G_year_of_passing, G_percentage, G_University,
Post_graduation, PG_year_of_passing, PG_percentage, PG_university,
mother_name, religion, category, semester, section, status,Photo) ;
values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
addstudent.setString(1,ScholarNo.getText());
addstudent.setString(2,StudentName.getText().trim());
addstudent.setString(3,AdmissionNo.getText().trim());
addstudent.setString(4,DateOfAdmission.getDate().toString());
addstudent.setString(5,FatherName.getText().trim());
addstudent.setString(6,Gender.getSelectedItem().toString().trim());
addstudent.setString(7, DOB.getDate().toString());
addstudent.setString(8,Address.getText().trim());
addstudent.setString(9,Session.getSelectedItem().toString());
addstudent.setString(10,ContactNo.getText().trim());
addstudent.setString(11,Email.getText().trim());
addstudent.setString(12,Course.getSelectedItem().toString().trim());
addstudent.setString(13,Branch.getSelectedItem().toString().trim());
addstudent.setString(14,DocumentSubmitted.getText().trim());
addstudent.setString(15,Nationality.getText().trim());
addstudent.setString(16,GuardianName.getText().trim());
addstudent.setString(17,GuardianContactNo.getText().trim());
addstudent.setString(18,GuardianAddress.getText().trim());
addstudent.setString(19,HS.getText().trim());
addstudent.setString(20,HSYOP.getText().trim());
addstudent.setString(21,HSPercentage.getText().trim());
addstudent.setString(22,HSBoard.getText().trim());
addstudent.setString(23,HSS.getText().trim());
addstudent.setString(24,HSSYOP.getText().trim());
addstudent.setString(25,HSSPercentage.getText().trim());
addstudent.setString(26,HSSBoard.getText().trim());
addstudent.setString(27,UG.getSelectedItem().toString().trim());
addstudent.setString(28,GYOP.getText().trim());
addstudent.setString(29,GPercentage.getText().trim());
addstudent.setString(30,GUniy.getText().trim());
addstudent.setString(31,PG.getSelectedItem().toString().trim());
addstudent.setString(32,PGYOP.getText().trim());
addstudent.setString(33,PGpercentage.getText().trim());
addstudent.setString(34,PGUniy.getText().trim());
addstudent.setString(35,MotherName.getText().trim());
addstudent.setString(36,Religion.getSelectedItem().toString().trim());
addstudent.setString(37,Category.getSelectedItem().toString().trim());
addstudent.setString(38,Semester.getSelectedItem().toString().trim());
addstudent.setString(39,Section.getSelectedItem().toString().trim());
addstudent.setString(40,Status.getSelectedItem().toString().trim());
addstudent.setBytes(41,person_image);
addstudent.executeUpdate();
} catch(Exception e) {
//e.printStackTrace();
JOptionPane.showMessageDialog(null, e);
}
Result of Stack
run:
java.lang.NullPointerException
at projectmanagment.frmStudentRegistration.btnupdateActionPerformed(frmStudentRegistration.java:895)
at projectmanagment.frmStudentRegistration.btnupdateActionPerformed(frmStudentRegistration.java:895)
at projectmanagment.frmStudentRegistration.access$300(frmStudentRegistration.java:25)
at projectmanagment.frmStudentRegistration$4.actionPerformed(frmStudentRegistration.java:563)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
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:6516)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3320)
at java.awt.Component.processEvent(Component.java:6281)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4872)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4698)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
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.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
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)
It got solved, error was regarding date which gave me null pointer Error, will post another Question for its answer so others are also benifited having same trouble

synthesizer error in java

First time App work fine.But when I click "Speech" button for second time It make errors
java.lang.IllegalThreadStateException
at java.lang.Thread.start(Thread.java:684)
at com.sun.speech.freetts.jsapi.FreeTTSSynthesizer.handleAllocate(FreeTTSSynthesizer.java:98)
at com.sun.speech.engine.BaseEngine.allocate(BaseEngine.java:219)
at text2speech.GUI.speechFile(GUI.java:141)
at text2speech.GUI.jButton2ActionPerformed(GUI.java:159)
at text2speech.GUI.access$100(GUI.java:24)
at text2speech.GUI$2.actionPerformed(GUI.java:61)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
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:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
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.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
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)
Here is the code.
public void speechFile(){
String context=jTextArea1.getText();
try
{
System.setProperty("freetts.voices","com.sun.speech.freetts.en.us.cmu_us_kal.KevinVoiceDirectory");
Central.registerEngineCentral("com.sun.speech.freetts.jsapi.FreeTTSEngineCentral");
Synthesizer synthesizer =Central.createSynthesizer(new SynthesizerModeDesc(Locale.US));
synthesizer.allocate();
synthesizer.resume();
synthesizer.speakPlainText(context, null);
synthesizer.waitEngineState(Synthesizer.QUEUE_EMPTY);
synthesizer.deallocate();
}
catch(IllegalArgumentException e)
{
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (AudioException e) {
e.printStackTrace();
} catch (EngineException e) {
e.printStackTrace();
}
}
The thing I don't understand is first it work fine.second time it makes errors.How to fix this.
I don't know much about this library or technique, but to me it seems odd that you would register the engine once for each use, and odd that you wouldn't reuse an existing synthesizer.
Have you tried creating the synthesizer once and using it twice?
to make the code read more than once, all you have to do to remove the synth.deallocate(); from your code, then you will be able to loop till you want.

strange exception in java sql update

I'm trying to edit a sql table using a java program. However, i get the following exception(includes stacktrace). The exception is a verystrange one, never encountered it before.
com.mysql.jdbc.exceptions.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '[,20,375,298x28,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmen' at line 1
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:936)
at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:2985)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1631)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3283)
at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1332)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1604)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1519)
at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:1504)
at transaction.EditClientTrans.clEditTrActionPerformed(EditClientTrans.java:259)
at transaction.EditClientTrans.access$300(EditClientTrans.java:23)
at transaction.EditClientTrans$4.actionPerformed(EditClientTrans.java:121)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
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:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:735)
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.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:708)
at java.awt.EventQueue$4.run(EventQueue.java:706)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:705)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:161)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:154)
at java.awt.WaitDispatchSupport$2.run(WaitDispatchSupport.java:182)
at java.awt.WaitDispatchSupport$4.run(WaitDispatchSupport.java:221)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.WaitDispatchSupport.enter(WaitDispatchSupport.java:219)
at java.awt.Dialog.show(Dialog.java:1082)
at java.awt.Component.show(Component.java:1651)
at java.awt.Component.setVisible(Component.java:1603)
at java.awt.Window.setVisible(Window.java:1014)
at java.awt.Dialog.setVisible(Dialog.java:1005)
at transaction.EditClientTrans$5.run(EditClientTrans.java:310)
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)
Here is the code:
private void clEditTrActionPerformed(java.awt.event.ActionEvent evt) {
try {
long bal = amtnum - downp;
payoption = (String) payOpt.getSelectedItem();
if(bal==0)
pstat = "Fully Paid";
else if((bal>0)&&(bal<amtnum))
pstat = "Partially Paid";
else if(bal==amtnum)
pstat = "Unpaid";
String sql = "update kusinanikambal.ctrans "
+ "set clname = '"+cliName.getText()
+"', contdet = '"+cliCNo.getText()
+"', date = '"+Date.getText()
+"', amt = "+amtnum
+", paidamt= "+down
+", bal = "+bal
+", paymethod = '"+payoption+"'"
+", paystat = '"+pstat+"'"
+ "where transno = "+ transNo.getText();
PreparedStatement pst = conn.prepareStatement(sql);
int rs = pst.executeUpdate();
JOptionPane.showMessageDialog(null,"Edit Successful");
super.setVisible(false);
} catch (SQLException ex) {
JOptionPane.showMessageDialog(null,ex);
ex.printStackTrace();
}
}
You've appended an Object (in this, some kind of component) as part of your query, which has used the object's toString method as the result. Can't tell which one as you've not provided that much information.
You should also consider using PreparedStatements instead of appending the query String together...

Java exception when trying to show Array

So I'm trying to create an array list that stores the shape type, size and color. Then I want it to output in the terminal. Here's what I have, but I keep getting exceptions:
if (e.getSource() == storeData) {
ShapeItem.add(shapeChoice.getSelectedItem()); //Add shape type
ShapeItem.add(ShapeSize); //Add shape size
ShapeItem.add(shapeColor); //Add shape color
}
else if (e.getSource() == showData) {
while (it.hasNext()) {
System.out.println(it.next());
}
}
And the declarations:
ArrayList ShapeItem = new ArrayList(); //Generic ArrayList to Store objects
Iterator it = ShapeItem.iterator(); //Iterator to go through the array
It seems it should work, but here's what happens:
(Sorry for the huge wall of text, but I have no idea what's important in exceptions)
Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:819)
at java.util.ArrayList$Itr.next(ArrayList.java:791)
at Main.actionPerformed(Main.java:140)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
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:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:696)
at java.awt.EventQueue$4.run(EventQueue.java:694)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:819)
at java.util.ArrayList$Itr.next(ArrayList.java:791)
at Main.actionPerformed(Main.java:140)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
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:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:696)
at java.awt.EventQueue$4.run(EventQueue.java:694)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:819)
at java.util.ArrayList$Itr.next(ArrayList.java:791)
at Main.actionPerformed(Main.java:140)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
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:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:696)
at java.awt.EventQueue$4.run(EventQueue.java:694)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException
at java.util.ArrayList$Itr.checkForComodification(ArrayList.java:819)
at java.util.ArrayList$Itr.next(ArrayList.java:791)
at Main.actionPerformed(Main.java:140)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2018)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2341)
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:6505)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3321)
at java.awt.Component.processEvent(Component.java:6270)
at java.awt.Container.processEvent(Container.java:2229)
at java.awt.Component.dispatchEventImpl(Component.java:4861)
at java.awt.Container.dispatchEventImpl(Container.java:2287)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4832)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4492)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4422)
at java.awt.Container.dispatchEventImpl(Container.java:2273)
at java.awt.Window.dispatchEventImpl(Window.java:2719)
at java.awt.Component.dispatchEvent(Component.java:4687)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:723)
at java.awt.EventQueue.access$200(EventQueue.java:103)
at java.awt.EventQueue$3.run(EventQueue.java:682)
at java.awt.EventQueue$3.run(EventQueue.java:680)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:87)
at java.awt.EventQueue$4.run(EventQueue.java:696)
at java.awt.EventQueue$4.run(EventQueue.java:694)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:693)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:244)
at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:147)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:139)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:97)
The problem is that you're creating the iterator when you create the ArrayList. The iterator will have been invalidated by you adding items to it. You should create the iterator when you need it, like this:
else if (e.getSource() == showData) {
Iterator it = ShapeItem.iterator();
while (it.hasNext()) {
System.out.println(it.next());
}
}
... and remove the Iterator instance variable entirely.
Or more idiomatically, just use an enhanced for loop:
else if (e.getSource() == showData) {
for (Object shape : ShapeItem) {
System.out.println(shape);
}
}
I would also suggest:
Encapsulating the type, size and colour into a single object e.g. type Shape, rather than storing three separate values of different types
Changing your variable name to be conventional (shapeItems or just shapes instead of ShapeItem)
Changing your variable to be private and possibly final
Possibly changing your variable type to be the interface List rather than the concrete ArrayList type
Using generics to indicate the type of the data
So:
private final List<Shape> shapes = new ArrayList<Shape>();
Then adding:
if (e.getSource() == storeData) {
shapes.add(new Shape(shapeChoice.getSelectedItem(),
shapeSize, shapeColor));
}
And displaying:
else if (e.getSource() == showData) {
for (Shape shape : shapes) {
System.out.println(shape);
}
}

Categories

Resources