I'm looking for a way around the problem with showAndWait call.
I've thought onFinishedProperty is fired when the animation process is over, still im unable to call showAndWait because of error saying that im trying to call it during animation process. Is there anyway to call my dialog right after finish of animation?
TextInputDialog dialog = new TextInputDialog("Litera");
dialog.setTitle("");
dialog.setHeaderText("");
dialog.setContentText("Wybierz literę:");
for(int i = 0 ; i<pieChartData.size();i++)
System.out.println(pieChartData.get(i));
RotateTransition rotateTransition = new RotateTransition();
rotateTransition.setDuration(Duration.millis(5000));
rotateTransition.setNode(fortuna);
rotateTransition.setCycleCount(1);
rotate.setOnAction(
(e)->{
fortuna.setRotate(0);
rotate.setDisable(true);
rotateTransition.setAutoReverse(false);
rotateTransition.setByAngle((int)(Math.random()*10800+360));
rotateTransition.play();
rotateTransition.onFinishedProperty().set(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
System.out.println(fortuna.getRotate());
Optional<String> result = dialog.showAndWait();
rotate.setDisable(false);
}
}
);
});
Exception in thread "JavaFX Application Thread" java.lang.IllegalStateException: showAndWait is not allowed during animation or layout processing
at javafx.controls/javafx.scene.control.Dialog.showAndWait(Unknown Source)
at Main$1.handle(Main.java:78)
at Main$1.handle(Main.java:1)
at javafx.graphics/javafx.animation.Animation.finished(Unknown Source)
at javafx.graphics/javafx.animation.AnimationAccessorImpl.finished(Unknown Source)
at javafx.graphics/com.sun.scenario.animation.shared.SingleLoopClipEnvelope.timePulse(Unknown Source)
at javafx.graphics/javafx.animation.Animation.doTimePulse(Unknown Source)
at javafx.graphics/javafx.animation.Animation$1.lambda$timePulse$0(Unknown Source)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at javafx.graphics/javafx.animation.Animation$1.timePulse(Unknown Source)
at javafx.graphics/com.sun.scenario.animation.AbstractMasterTimer.timePulseImpl(Unknown Source)
at javafx.graphics/com.sun.scenario.animation.AbstractMasterTimer$MainLoop.run(Unknown Source)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(Unknown Source)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulse(Unknown Source)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.pulseFromQueue(Unknown Source)
at javafx.graphics/com.sun.javafx.tk.quantum.QuantumToolkit.lambda$runToolkit$11(Unknown Source)
at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at javafx.graphics/com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at javafx.graphics/com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(Unknown Source)
at java.base/java.lang.Thread.run(Unknown Source)
Related
I'm writing a simple application with java and trying to play sounds but I can't get it to work when I create the Media object it throws
java.lang.reflect.InvocationTargetException , the file name is correct , and i tried the full file path name and i get the same error
my code is :
`
public class Try extends Application {
#Override
public void start(Stage primaryStage) throws Exception {
Pane pane = new Pane () ;
Button b = new Button("click here ") ;
Media m = new Media ("music.mp3");
MediaPlayer md = new MediaPlayer(m) ;
b.setOnAction(e -> {
md.play();
System.out.println("clicked");
});
pane.getChildren().add(b) ;
Scene s = new Scene(pane , 300 ,300 ) ;
primaryStage.setScene(s);
primaryStage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
i tried .wav files and get same error .
the full error :
`
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:917)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$159(LauncherImpl.java:182)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalArgumentException: uri.getScheme() == null! uri == 'music.mp3'
at com.sun.media.jfxmedia.locator.Locator.<init>(Locator.java:218)
at javafx.scene.media.Media.<init>(Media.java:393)
at ttry.Try.start(Try.java:17)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$166(LauncherImpl.java:863)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$179(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl.lambda$null$177(PlatformImpl.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$178(PlatformImpl.java:294)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$152(WinApplication.java:177)
... 1 more
Exception running application ttry.Try
`
I've watched a lot of posts about playing YouTube videos, and also watched Oracle learning tutorials. They used this code and it worked perfectly to them, but I get errors. And can't find a way to fix it.
#Override
public void start(Stage window) throws Exception
{
Media media = new Media("https://www.youtube.com/watch?v=Q0oIoR9mLwc");
MediaPlayer player = new MediaPlayer(media);
MediaView view = new MediaView(player);
player.setAutoPlay(true);
StackPane sp = new StackPane(view);
Scene sc = new Scene(sp,500,500);
window.setScene(sc);
window.show();
}
ERRORS I GET
Exception in Application start method
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(Unknown Source)
at com.sun.javafx.application.LauncherImpl.launchApplication(Unknown Source)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.RuntimeException: Exception in Application start method
at com.sun.javafx.application.LauncherImpl.launchApplication1(Unknown Source)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$155(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.UnsupportedOperationException: Unsupported protocol "https"
at com.sun.media.jfxmedia.locator.Locator.<init>(Unknown Source)
at javafx.scene.media.Media.<init>(Unknown Source)
at PlayVideo.Main.start(Main.java:34)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$162(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$175(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$173(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
... 1 more
Exception running application PlayVideo.Main
I also checked this link on stackoverflow but couldn't find solution. Link
Also tried it this way but video won't load.
#Override public void start(Stage stage) throws Exception {
WebView webview = new WebView();
webview.getEngine().load(
"https://www.youtube.com/watch?v=jaPUbzfJx2A"
);
webview.setPrefSize(640, 390);
stage.setScene(new Scene(webview));
stage.show();
}
}
I'm getting NullPointerException when using org.controlsfx.control.RangeSlider. Here is the simple code example:
package experimental_main;
import org.controlsfx.control.RangeSlider;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
public class Experimental_start extends Application
{
public static void main(String[] args)
{
launch(args);
}
#Override
public void start(Stage primaryStage) throws Exception
{
Button button = new Button("Click me");
RangeSlider rangeSlider = new RangeSlider(0, 10, 2, 4);
BorderPane borderPane = new BorderPane();
borderPane.setCenter(rangeSlider);
borderPane.setTop(button);
Scene scene = new Scene(borderPane, 300, 300);
primaryStage.setScene(scene);
primaryStage.show();
}
}
The exception occurs when pressing Tab while right thumb of RangeSlider is focused or pressing Shift+Tab while its left thumb is focused. These key pressings cause to lose focus from RangeSlider as expected, but this action also causes NullPointerException. Here is exception's stack trace:
Exception in thread "JavaFX Application Thread" java.lang.NullPointerException
at com.sun.javafx.scene.traversal.TraversalEngine.select(Unknown Source)
at impl.org.controlsfx.skin.RangeSliderSkin$5.handle(RangeSliderSkin.java:150)
at impl.org.controlsfx.skin.RangeSliderSkin$5.handle(RangeSliderSkin.java:132)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEventImpl(Unknown Source)
at com.sun.javafx.event.EventUtil.fireEvent(Unknown Source)
at javafx.event.Event.fireEvent(Unknown Source)
at javafx.scene.Scene$KeyHandler.process(Unknown Source)
at javafx.scene.Scene$KeyHandler.access$1800(Unknown Source)
at javafx.scene.Scene.impl_processKeyEvent(Unknown Source)
at javafx.scene.Scene$ScenePeerListener.keyEvent(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$KeyEventNotification.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleKeyEvent$353(Unknown Source)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(Unknown Source)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleKeyEvent(Unknown Source)
at com.sun.glass.ui.View.handleKeyEvent(Unknown Source)
at com.sun.glass.ui.View.notifyKey(Unknown Source)
at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
at com.sun.glass.ui.win.WinApplication.lambda$null$148(Unknown Source)
at java.lang.Thread.run(Unknown Source)
There is no exception when pressing Tab (or Shift+Tab) with a view to make RangeSlider's thumb focused.
Am I doing something wrong or it's a bug? Is there alternative to RangeSlider class realizations?
This listener of the RangeSliderSkin seems to cause the NPE:
EventHandler<KeyEvent> keyEventHandler = new EventHandler<KeyEvent>() {
#Override public void handle(KeyEvent event) {
if (KeyCode.TAB.equals(event.getCode())) {
if (lowThumb.isFocused()) {
if (event.isShiftDown()) {
lowThumb.setFocus(false);
new ParentTraversalEngine(rangeSlider).select(rangeSlider, Direction.PREVIOUS);
} else {
lowThumb.setFocus(false);
highThumb.setFocus(true);
}
event.consume();
} else if (highThumb.isFocused()) {
if(event.isShiftDown()) {
highThumb.setFocus(false);
lowThumb.setFocus(true);
} else {
highThumb.setFocus(false);
new ParentTraversalEngine(rangeSlider).select(rangeSlider, Direction.NEXT);
}
event.consume();
}
}
}
};
To be more specific, the line new ParentTraversalEngine(rangeSlider).select(rangeSlider, Direction.NEXT);
ParentTraversalEngine is initalized without an Algorithm argument, so calling select(rangeSlider, Direction.NEXT) is causing a NPE, as it is supposed to:
Throws:
java.lang.NullPointerException - if there is no algorithm
javadoc
The bug is fixed beginning from version 8.40.13.
I'm trying to integrate Java Skype API in my program. I found an example code in the API documentation that was using Java listeners to get the current call status. I implemented the code in my program and I need to call a function (addLog function) every time the Skype call status changes, but when I call such function, the console is showing me a "Exception in thread "AsyncSkypeMessageSender-18" java.lang.IllegalStateException".
When I use the command System.out.ln inside the listener, it is working how it is supposed to, without any errors, but every time I call a function inside the listener, it gives me an error.
Do you guys know something to solve my problem, I thought it may be a thread related issue, but I'm not familiar with Java programming.
The code is:
public void addLog(String log){
Date date = new Date();
SimpleDateFormat datetime = new SimpleDateFormat("dd/MM hh:mm:ss");
String datetimeString = datetime.format(date);
logArea.appendText(datetimeString + " > " + log);
}
public void makeCall() throws SkypeException {
Skype.call("echo123");
Skype.setDaemon(false);
//Skype.setDebug(true);
System.out.println(" --------------------------------");
System.out.println(" ------ Fazendo ligação... ------");
System.out.println(" --------------------------------");
SkypeVoicer skypeVoicer = new SkypeVoicer();
skypeVoicer.addLog("Iniciou ligação\n");
Skype.addCallListener(new CallAdapter() {
public void callMaked(Call makedCall){
makedCall.addCallStatusChangedListener(new CallStatusChangedListener(){
#Override
public void statusChanged(Status status) throws SkypeException {
if(status == Status.FINISHED){
System.out.println("Finalizou, chamada de " + makedCall.getDuration() + " segundos...");
skypeVoicer.addLog("\nFinalizou em "+makedCall.getDuration()+" segundos");
makedCall.removeCallStatusChangedListener(this);
}
else if(status == Status.CANCELLED){
System.out.println("Cancelado");
}
else if(status == Status.ROUTING){
System.out.println("Redirecionando...");
}
else if(status == Status.RINGING){
System.out.println("Tocando...");
}
else if(status == Status.INPROGRESS){
System.out.println("Em Progresso...");
skypeVoicer.addLog("Em Progresso...");
}
}
});
}
});
}
The full stack trace is this one bellow:
Exception in thread "AsyncSkypeMessageSender-18"
java.lang.IllegalStateException: Not on FX application thread;
currentThread = AsyncSkypeMessageSender-18 at
com.sun.javafx.tk.Toolkit.checkFxUserThread(Unknown Source) at
com.sun.javafx.tk.quantum.QuantumToolkit.checkFxUserThread(Unknown
Source) at javafx.scene.Scene.addToDirtyList(Unknown Source) at
javafx.scene.Node.addToSceneDirtyList(Unknown Source) at
javafx.scene.Node.impl_markDirty(Unknown Source) at
javafx.scene.shape.Shape.impl_markDirty(Unknown Source) at
javafx.scene.text.Text.geomChanged(Unknown Source) at
javafx.scene.text.Text.impl_geomChanged(Unknown Source) at
javafx.scene.text.Text.needsTextLayout(Unknown Source) at
javafx.scene.text.Text.needsFullTextLayout(Unknown Source) at
javafx.scene.text.Text.access$200(Unknown Source) at
javafx.scene.text.Text$2.invalidated(Unknown Source) at
javafx.beans.property.StringPropertyBase.markInvalid(Unknown Source)
at javafx.beans.property.StringPropertyBase.set(Unknown Source) at
javafx.beans.property.StringPropertyBase.set(Unknown Source) at
javafx.scene.text.Text.setText(Unknown Source) at
com.sun.javafx.scene.control.skin.TextAreaSkin.lambda$new$231(Unknown
Source) at
com.sun.javafx.scene.control.skin.TextAreaSkin$$Lambda$172/1330104206.invalidated(Unknown
Source) at
com.sun.javafx.binding.ExpressionHelper$Generic.fireValueChangedEvent(Unknown
Source) at
com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(Unknown
Source) at
javafx.scene.control.TextInputControl$TextProperty.fireValueChangedEvent(Unknown
Source) at
javafx.scene.control.TextInputControl$TextProperty.markInvalid(Unknown
Source) at
javafx.scene.control.TextInputControl$TextProperty.invalidate(Unknown
Source) at
javafx.scene.control.TextInputControl$TextProperty.access$1300(Unknown
Source) at
javafx.scene.control.TextInputControl.lambda$new$163(Unknown Source)
at
javafx.scene.control.TextInputControl$$Lambda$77/323047656.invalidated(Unknown
Source) at
com.sun.javafx.binding.ExpressionHelper$SingleInvalidation.fireValueChangedEvent(Unknown
Source) at
com.sun.javafx.binding.ExpressionHelper.fireValueChangedEvent(Unknown
Source) at
javafx.scene.control.TextArea$TextAreaContent.insert(Unknown Source)
at javafx.scene.control.TextInputControl.replaceText(Unknown Source)
at javafx.scene.control.TextInputControl.insertText(Unknown Source)
at javafx.scene.control.TextInputControl.appendText(Unknown Source)
at SkypeVoicer.addLog(SkypeVoicer.java:186) at
SkypeVoicer$2$1.statusChanged(SkypeVoicer.java:157) at
com.skype.Call.fireStatusChanged(Call.java:339) at
com.skype.ConnectorListenerImpl.messageReceived(ConnectorListenerImpl.java:61)
at
com.skype.connector.Connector.fireMessageEvent(Connector.java:1160)
at com.skype.connector.Connector.access$500(Connector.java:37) at
com.skype.connector.Connector$13.run(Connector.java:1139) at
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at
java.lang.Thread.run(Unknown Source)
I'm writing a code that involves JFrame, and a thread.
The thread should take the text from a text field and write it into text area.
I have 4 buttons as follows:
"Start" to start the thread.
"Stop" which stops the thread.
"Pause" which pause and continues the thread.
and "Exit" which stops the thread and exits the program.
I've created the thread and implemented "run()" function in frame's constructor, here it is:
WritingThread = new Thread(new Runnable() {
#Override
public void run() {
String s = WrittenText.getText();
while(true)
{
for(int i = 0; i < 4; i++)
{
for(int j = 0; j < s.length(); j++)
{
WritingArea.append("" + s.charAt(j));
try {
Thread.sleep((int)ThreadSpeedSpinner.getValue());
} catch (InterruptedException e) {
e.printStackTrace();
}
}
WritingArea.append("\n");
}
WritingArea.setText("");
}
}
});
and these are the buttons:
JButton btnStart = new JButton("Start");
btnStart.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(!WritingThread.isAlive())
WritingThread.start();
}
});
JButton btnStop = new JButton("Stop");
btnStop.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(WritingThread.isAlive())
WritingThread.stop();
}
});
btnPause = new JButton("Pause");
btnPause.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
if(!isPaused)
{
if(WritingThread.isAlive())
{
WritingThread.suspend();
btnPause.setText("Continue");
isPaused = true;
}
}
else
{
WritingThread.resume();
btnPause.setText("Pause");
}
}
});
JButton btnExit = new JButton("Exit");
btnExit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
WritingThread.stop();
System.exit(0);
}
});
I have two problems showing up:
When I use stop(), suspend(), or resume(), I get a warning says "The method from the type Thread is deprecated".
When I run the program, I start the thread, then stop it, then try to start it I have this exception
Exception in thread "AWT-EventQueue-0" java.lang.IllegalThreadStateException
at java.lang.Thread.start(Unknown Source)
at com.HomeWork.HomeWork5$6.actionPerformed(HomeWork5.java:140)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$200(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.awt.EventQueue$4.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
I don't want direct answers, I want to understand why I'm getting these errors, and if there any resources I should go through.
P.S. I searched for an answer a lot and didn't get anything explaining this problem.
Thanks
Threads acquire lock on objects. And the most important part of multithreading
is to safely interweave the threads, so that all the threads can use the resource (object).
If not dealt with correctly, it leads to deadlock.
When you use stop(), you are killing the thread. That thread is gone forever. It
may lead the objects, that stopped thread had acquired, in a inconsistent state.
suspend() is deprecated, because once the thread is suspended other threads won't get the
resource, since the suspended thread holds a lock on it.
The image below describes how threads should be correctly used.
Use sleep(), wait(), and notify() for interleaving the threads efficiently.