public class MesssageBoxQuestionIconYESNOButton {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
//This is added to be able to run JUnit in this java class
JUnitCore junit = new JUnitCore();
Result result;
int style = SWT.ICON_WARNING | SWT.YES | SWT.NO;
MessageBox messageBox = new MessageBox(shell, style);
messageBox.setMessage("Would you like to start the test?");
int rc = messageBox.open();
if(rc == SWT.YES)
{
//Must add in the .class else it will not work
result = junit.run(testMyCode.class);
//This part is to ask if the user want to repeat the test again
Display display1 = new Display();
Shell shell1 = new Shell(display);
int style1 = SWT.ICON_WARNING | SWT.YES | SWT.NO;
MessageBox messageBox1 = new MessageBox(shell, style);
messageBox1.setMessage("Would you like to repeat the test?");
int rc1 = messageBox.open();
if(rc1 == SWT.YES)
{
result = junit.run(testMyCode.class);
}
else
{
MessageBox messageBox2 = new MessageBox(shell, style);
messageBox2.setMessage("Thank You For Using");
display1.dispose();
}
}
else
{
display.dispose();
}
}
}
이것은 현재 가지고있는 코드입니다.중첩 된 SWT 메시지 상자에 오류가 있습니다.
- 그들은 예, 완료 JUnit 테스트 후 JUnit 테스트
- 를 실행하면 테스트를
- 를 시작하려면 사용자에게 질문 그래서이 내가하고 싶은 것입니다. 테스트를 다시 반복 할 것인지 묻는 메시지를 사용자에게 묻습니다.
이 코드에서는 모든 것이 3 단계까지 제대로 작동합니다.
이Exception in thread "main" org.eclipse.swt.SWTException: Invalid thread access
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.SWT.error(Unknown Source)
at org.eclipse.swt.widgets.Display.checkDisplay(Unknown Source)
at org.eclipse.swt.widgets.Display.create(Unknown Source)
at org.eclipse.swt.graphics.Device.<init>(Unknown Source)
at org.eclipse.swt.widgets.Display.<init>(Unknown Source)
at org.eclipse.swt.widgets.Display.<init>(Unknown Source)
사람이 오해 무엇을보고 도울 수 :
이것은 내가받은 오류인가? 주셔서 감사합니다
이 오류는내가 너무, 몇 가지 수정을 만든 새로운
Display
... 생성에 의해 발생하므로이 같은 시도했다
하나의 '디스플레이' –
만 만들어야합니다. 하나의 디스플레이를 공유한다는 의미입니까? –
일반적인 SWT 애플리케이션은 모든 것에 사용되는 단일 'Display'객체 만 작성합니다. 같은 스레드에서 두 번째 표시 객체를 만들 수없고 일부 플랫폼 (예 : macOS)에서는 두 번째 표시 객체를 전혀 만들 수 없습니다. –