I'm getting this exception when I run my code. Even though the code runs fine, I'm getting some exceptions on the terminal
Exception in thread "AWT-EventQueue-1" java.lang.IllegalThreadStateException
at java.lang.Thread.start(Thread.java:708)
at SR.start(SR.java:38)
at SR.mouseClicked(SR.java:212)
at java.awt.Component.processMouseEvent(Component.java:6536)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Window.processEvent(Window.java:2025)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at org.GNOME.Accessibility.AtkWrapper$5.dispatchEvent(AtkWrapper.java:700)
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)
What am i doing wrong??
My start() method
private void start() throws IllegalStateException {
if (HelperThread == null)
HelperThread = new Thread(this);
HelperThread.start();
}
You appear to be starting the same Thread twice, which is not allowed.
If you're looking to reuse the same thread, I would recommend creating an ExecutorService instead.
The problem is that if HelperThread is not null (it already exists) and you call HelperThread.start() is tries to start() a thread that has already started or finished it's processing. If you want to restart processing, you'll have to stop the thread first. To do this gracefully, use a while (running) { } pattern in the actual thread. Then, int the start()-method, set the flag to false, wait for the thread to die and then start a new thread:
private void start() throws IllegalStateException {
if (HelperThread != null) {
running = false;
HelperThread.join(); // wait for it to die...
}
// Start fresh...
HelperThread = new Thread(this);
HelperThread.start();
}
Also, as a side note, avoid using capital letters as the first letters for variables. It should rather be "helperThread".
Related
I have a JavaFX application which contains a SwingNode with an OpenGL app in it.
Most of the time, everything is fine, but sometimes when I close the window I get this error:
Catched Exception on thread AWT-EventQueue-0
javax.media.nativewindow.NativeWindowException: DC not released: GDISurface[ displayHandle 0x0
, surfaceHandle 0xffffffffe201277c
, size 2560x1361
, UOB[ OWNS_SURFACE | OWNS_DEVICE | WINDOW_INVISIBLE ]
, WindowsWGLGraphicsConfiguration[DefaultGraphicsScreen[WindowsGraphicsDevice[type .windows, connection decon, unitID 0, handle 0x0, owner false, NullToolkitLock[]], idx 0], pfdID 7, ARB-Choosen true,
requested GLCaps[rgba 8/8/8/8, opaque, accum-rgba 0/0/0/0, dp/st/ms 24/0/0, one, mono , hw, GLProfile[GL4bc/GL4bc.hw], on-scr[.]],
chosen GLCaps[wgl vid 7 arb: rgba 8/8/8/8, opaque, accum-rgba 0/0/0/0, dp/st/ms 24/0/0, one, mono , hw, GLProfile[GL4bc/GL4bc.hw], offscr[fbo]]]
, surfaceLock <4a7b3290, 6de653ec>[count 1, qsz 0, owner <AWT-EventQueue-0>]
, GDIDummyUpstreamSurfaceHook[ 2560x1361]
, upstreamSurface false ], isWindow false, werr 0, thread: AWT-EventQueue-0
at jogamp.nativewindow.windows.GDISurface.unlockSurfaceImpl(GDISurface.java:121)
at jogamp.nativewindow.ProxySurfaceImpl.unlockSurface(ProxySurfaceImpl.java:226)
at jogamp.opengl.GLDrawableImpl.unlockSurface(GLDrawableImpl.java:334)
at jogamp.opengl.GLContextImpl.release(GLContextImpl.java:354)
at jogamp.opengl.GLContextImpl.release(GLContextImpl.java:316)
at jogamp.opengl.GLDrawableHelper.invokeGLImpl(GLDrawableHelper.java:1132)
at jogamp.opengl.GLDrawableHelper.invokeGL(GLDrawableHelper.java:994)
at javax.media.opengl.awt.GLJPanel$OffscreenBackend.doPaintComponent(GLJPanel.java:1731)
at javax.media.opengl.awt.GLJPanel.paintComponent(GLJPanel.java:538)
at javax.swing.JComponent.paint(JComponent.java:1056)
at javax.swing.JComponent.paintChildren(JComponent.java:889)
at javax.swing.JComponent.paint(JComponent.java:1065)
at sun.swing.JLightweightFrame$3.paint(JLightweightFrame.java:309)
at javax.swing.JComponent.paintToOffscreen(JComponent.java:5210)
at javax.swing.RepaintManager.paint(RepaintManager.java:1275)
at javax.swing.JComponent._paintImmediately(JComponent.java:5158)
at javax.swing.JComponent.paintImmediately(JComponent.java:4969)
at javax.swing.JComponent.paintImmediately(JComponent.java:4950)
at javax.swing.RepaintManager$4.run(RepaintManager.java:831)
at javax.swing.RepaintManager$4.run(RepaintManager.java:814)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:814)
at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:789)
at javax.swing.RepaintManager.prePaintDirtyRegions(RepaintManager.java:738)
at javax.swing.RepaintManager.access$1200(RepaintManager.java:64)
at javax.swing.RepaintManager$ProcessingRunnable.run(RepaintManager.java:1732)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
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)
I searched what it could be about, but I can't find anything. Does anybody have an idea of why this happens ? Here is the code I use to close the app:
// Close operation
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
#Override
public void handle(WindowEvent t) {
Platform.exit();
System.exit(0);
}
});
i am not sure but you are doing Platform.exit() that force Application.lauch() to return so you should put System.exit() in the main() function, because JavaFX runtime close when you do Platform.exit() and stop() method is called but in the same time System.exit() is called
I am trying to setup a kafka producer with KafkaAvroSerialzer for value. And I am facing this error wheneve rit is trying to created the Producer. I am using all the jars provided in confluent 5.2.1
java.lang.NoClassDefFoundError: Could not initialize class io.confluent.kafka.schemaregistry.client.rest.RestService
at io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient.<init>(CachedSchemaRegistryClient.java:104)
at io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient.<init>(CachedSchemaRegistryClient.java:81)
at io.confluent.kafka.serializers.AbstractKafkaAvroSerDe.configureClientProperties(AbstractKafkaAvroSerDe.java:53)
at io.confluent.kafka.serializers.AbstractKafkaAvroSerializer.configure(AbstractKafkaAvroSerializer.java:43)
at io.confluent.kafka.serializers.KafkaAvroSerializer.configure(KafkaAvroSerializer.java:48)
at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:370)
at org.apache.kafka.clients.producer.KafkaProducer.<init>(KafkaProducer.java:298)
at swing.KafkaUtilityPanel.sendMessage(KafkaUtilityPanel.java:229)
at swing.KafkaUtilityPanel.access$1200(KafkaUtilityPanel.java:32)
at swing.KafkaUtilityPanel$4.actionPerformed(KafkaUtilityPanel.java:164)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
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:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
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)
Producer
This is the producer part I have added and it is failing at trying to create the kafka producer with KafkaAvroSerializer.
try {
//Configure connection properties
Properties producerConfig = createKafkaProducerProperties(environment);
//Create Kafka Producer
try (KafkaProducer<String, GenericRecord> myProducer = new KafkaProducer<>(producerConfig)) {
//Create ProducerRecord
Schema schema = new Schema.Parser().parse(new File("src/main/resources/investorOnboarding.avsc"));
GenericRecordBuilder genericRecordBuilder = new GenericRecordBuilder(schema);
GenericData.Record genericRecord = genericRecordBuilder.build();
final ProducerRecord<String, GenericRecord> myProducerRecord = new ProducerRecord<>(topicName.getCode(), genericRecord);
//Send the message
myProducer.send(myProducerRecord, new Callback() {
#Override
public void onCompletion(RecordMetadata metadata, Exception exception) {
if(exception == null){
alertSuccessStatus("Message has been successfully sent to Kafka");
}
}
});
//Disconnect
myProducer.close();
}
} catch (Exception ex) {
logger.info(ex.getMessage());
}
}
private Properties createKafkaProducerProperties(Environment implementation) throws UnknownHostException, PasswordProviderException {
Properties producerConfig = new Properties();
producerConfig.put("client.id", InetAddress.getLocalHost().getHostName());
producerConfig.put("bootstrap.servers", implementation.getBootStrapServers());
producerConfig.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
producerConfig.put("value.serializer", "io.confluent.kafka.serializers.KafkaAvroSerializer");
producerConfig.put("schema.registry.url", "http://localhost:8085");
Jars Added
You need to use kafka-schema-registry-client, and I don't think you need kafka-schema-registry.
In any case, I'd strongly recommend you use Maven or Gradle to manage dependencies for any Java project
https://docs.confluent.io/current/clients/install.html#installation-maven
In Java why do I get java.lang.IllegalStateException: cannot open system clipboard ?
This was running on Windows using Java 1.8.0_181 25.181-b13
java.lang.IllegalStateException: cannot open system clipboard
at sun.awt.windows.WClipboard.openClipboard(Native Method)
at sun.awt.datatransfer.SunClipboard.getClipboardFormatsOpenClose(SunClipboard.java:327)
at sun.awt.datatransfer.SunClipboard.isDataFlavorAvailable(SunClipboard.java:188)
at com.jthink.songkong.ui.startdialog.editsongs.EditSongsTable$PasteAction$1.flavorsChanged(EditSongsTable.java:170)
at sun.awt.datatransfer.SunClipboard$1SunFlavorChangeNotifier.run(SunClipboard.java:441)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:311)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:74)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:205)
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)
PasteAction methods is
public PasteAction(JTable tbl)
{
putValue(NAME, TextLabel.PASTEBUTTON.getMsg());
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
table = tbl;
final Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
cb.addFlavorListener(new FlavorListener()
{
#Override
public void flavorsChanged(FlavorEvent e)
{
try
{
setEnabled(cb.isDataFlavorAvailable(CellTransferable.CELL_DATA_FLAVOR)
|| cb.isDataFlavorAvailable(DataFlavor.stringFlavor));
}
catch(IllegalArgumentException iae)
{
MainWindow.logger.log(Level.SEVERE, iae.getMessage(), iae);
}
}
});
setEnabled(cb.isDataFlavorAvailable(CellTransferable.CELL_DATA_FLAVOR)
|| cb.isDataFlavorAvailable(DataFlavor.stringFlavor));
}
This happens when the Java app is notified that it has lost ownership, so it sometimes needs to allow a small amount of time for the clipboard to be "ready." By adding a very short sleep command to the method, we will be able to avoid the runtime exceptions. Please go to below link for more information
https://coderanch.com/t/377833/java/listen-clipboard
This question already has answers here:
ClassNotFoundException com.mysql.jdbc.Driver [duplicate]
(21 answers)
Closed 4 years ago.
I am making a program for the interviewers to submit their marks for a particular candidate. The interviews are on 5.7.18 and I have to submit the program before Tuesday/Wednesday. I am unable to connect to the MySQL database. I think there is some problem in user creation. The marks entered from 5 different PCs should go to a MySQL database in a different PC
Here is my url/password/username -
private static final String URL = "jdbc:mysql://192.168.1.35:3306/interview";
private static final String USER = "root";
private static final String PASSWORD = "ubuntu";
Here is my JAVA code -
try {
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection(URL, USER, PASSWORD);
JOptionPane.showMessageDialog(null,"Connection Established!","Alert", JOptionPane.INFORMATION_MESSAGE);
String q1="select username from users";
Statement st = con.createStatement();
String usr=jTextField2.getText();
String psw=(new String(jPasswordField1.getPassword()));
ResultSet rs = st.executeQuery(q1);
boolean flag_usr=false;
while(rs.next())
{
if(usr.equals(rs.getString("username")))
{
flag_usr=true;
}
}
if(flag_usr==true)
{
String q2="select password from users";
ResultSet rs1 = st.executeQuery(q2);
boolean flag_psw=false;
while(rs1.next())
{
if(psw.equals(rs1.getString("password")))
{
this.dispose();
JOptionPane.showMessageDialog(null,"Login successful!","Alert", JOptionPane.INFORMATION_MESSAGE);
new Marks().setVisible(true);
}
}
}
}
catch(Exception e)
{
e.printStackTrace();
}
And I am getting this error on clicking login button in whose function
the above code is written -
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at interview.portal.Login.jButton1ActionPerformed(Login.java:178)
at interview.portal.Login.access$000(Login.java:21)
at interview.portal.Login$1.actionPerformed(Login.java:81)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:2022)
at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2348)
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:6533)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3324)
at java.awt.Component.processEvent(Component.java:6298)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4888)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4525)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4466)
at java.awt.Container.dispatchEventImpl(Container.java:2280)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
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)
BUILD SUCCESSFUL (total time: 5 seconds)
It seems the mysql connectivity library is not included in the project. Solve the problem following one of the proposed solutions:
Refer
java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Eclipse
Download a MySQL Connector/J and add the .jar to your classpath.
I want to make a documentListener that if I type in the JTextField : txt_ip4class and match regex of IPv4 format it will change the JComboBox : box_ip4class content.
If the content is changed (itemStateChanged), range of IP Class will be written down to JTextField : txt_rangeclass, and bit usage will be write down to `JTextField : txt_bitclass``*.
I have succeeded in this method, but with a classic method (using jButton), but I failed in this method using documentListener. Only JComboBox : box_ip4Class changed.
My code, applying documentListener to txt_ip4class:
txt_ip4class.getDocument().addDocumentListener(new DocumentListener() {
#Override
public void insertUpdate(DocumentEvent e) {
logUpdate();
}
#Override
public void removeUpdate(DocumentEvent e) {
logUpdate();
}
#Override
public void changedUpdate(DocumentEvent e) {
logUpdate();
}
void logUpdate() {
Runnable doHighlight = new Runnable() {
#Override
public void run() {
String aTxt = txt_ip4class.getText();
classValue = 1;
if (!aTxt.matches("\\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\\.|$)){4}\\b")) {
classValue = 0;
} else if (aTxt.matches("\\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\\.|$)){4}\\b")) {
try {
classW.classMain(classValue, box_ip4class, txt_ip4class, txt_rangeclass, txt_bitclass);
} catch (IllegalStateException e) {
}
}
}
};
SwingUtilities.invokeLater(doHighlight);
}
});
classW.Main contains two conditions, if zero it will set other fields based on jComboBox (txt_ip4class will be replaced), if one it should be set jComboBox choosing an option. And from that option, it should do like option zero
Full code (I export these files from Netbeans project to zip):
Succeed method which using jButton to execute
Failed method which using documentListener without jButton
Full exception stacktrace is here
or
Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Attempt to mutate in notification
at javax.swing.text.AbstractDocument.writeLock(AbstractDocument.java:1338)
at javax.swing.text.AbstractDocument.replace(AbstractDocument.java:658)
at javax.swing.text.JTextComponent.setText(JTextComponent.java:1669)
at engines.ClassW.setFromCombo(ClassW.java:140)
at interfaces.Netgui$1.logUpdate(Netgui.java:63)
at interfaces.Netgui$1.insertUpdate(Netgui.java:41)
at javax.swing.text.AbstractDocument.fireInsertUpdate(AbstractDocument.java:201)
at javax.swing.text.AbstractDocument.handleInsertString(AbstractDocument.java:748)
at javax.swing.text.AbstractDocument.insertString(AbstractDocument.java:707)
at javax.swing.text.PlainDocument.insertString(PlainDocument.java:130)
at javax.swing.text.AbstractDocument.replace(AbstractDocument.java:669)
at javax.swing.text.JTextComponent.replaceSelection(JTextComponent.java:1328)
at javax.swing.text.DefaultEditorKit$DefaultKeyTypedAction.actionPerformed(DefaultEditorKit.java:884)
at javax.swing.SwingUtilities.notifyAction(SwingUtilities.java:1663)
at javax.swing.JComponent.processKeyBinding(JComponent.java:2882)
at javax.swing.JComponent.processKeyBindings(JComponent.java:2929)
at javax.swing.JComponent.processKeyEvent(JComponent.java:2845)
at java.awt.Component.processEvent(Component.java:6310)
at java.awt.Container.processEvent(Container.java:2236)
at java.awt.Component.dispatchEventImpl(Component.java:4889)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1954)
at java.awt.DefaultKeyboardFocusManager.dispatchKeyEvent(DefaultKeyboardFocusManager.java:806)
at java.awt.DefaultKeyboardFocusManager.preDispatchKeyEvent(DefaultKeyboardFocusManager.java:1074)
at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:945)
at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:771)
at java.awt.Component.dispatchEventImpl(Component.java:4760)
at java.awt.Container.dispatchEventImpl(Container.java:2294)
at java.awt.Window.dispatchEventImpl(Window.java:2746)
at java.awt.Component.dispatchEvent(Component.java:4711)
at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:758)
at java.awt.EventQueue.access$500(EventQueue.java:97)
at java.awt.EventQueue$3.run(EventQueue.java:709)
at java.awt.EventQueue$3.run(EventQueue.java:703)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:90)
at java.awt.EventQueue$4.run(EventQueue.java:731)
at java.awt.EventQueue$4.run(EventQueue.java:729)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:80)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:728)
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)
BUILD SUCCESSFUL (total time: 19 seconds)
===============EDIT 1============
Thanks to #MarkRotteveel
And this post
This problem is fixed, but another problem is exist..
Code in the doHighlight is running in a loop.
===============EDIT 2============
Updated the code.
doHighlight no longer looping when the condition doesn't equal the regex.
but still doing loop when the condition equals.