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
...作成によって引き起こされるので、このような何かしようとした
1つの「ディスプレイ」 –
を作成する必要があります。 –
通常のSWTアプリケーションでは、すべてに使用される単一の 'Display'オブジェクトしか作成されません。同じスレッド上に2番目の表示オブジェクトを作成することは決してできず、一部のプラットフォーム(たとえばmacOS)では、2番目の表示オブジェクトをまったく作成することはできません。 –