사용자 지정 대화 상자가 나타납니다. 나는 EDT에 나는 다음과 같은 오류 얻을 할 메서드를 호출하려고하면 이클립스에서 내 프로젝트를 정리하고, 나는 EDT에 메소드를 호출하는 것을 알아 냈 일부 절연 테스트를 수행 한 후EDT에서이 메서드를 호출하면 컴파일 오류가 발생하는 이유는 무엇입니까?
Exception in thread "AWT-EventQueue-0" java.lang.Error: Unresolved compilation problem:
at danind.com.gmail_coem.ui.CredentialEditor.promptPossibleDialog(CredentialEditor.java:29)
at danind.com.gmail_coem.ui.HomeScreen$ConfigureDatabase.<init>(HomeScreen.java:281)
at danind.com.gmail_coem.ui.HomeScreen.configureDatabase(HomeScreen.java:230)
at danind.com.gmail_coem.ui.HomeScreen.lambda$1(HomeScreen.java:105)
at danind.com.gmail_coem.ui.HomeScreen$$Lambda$7/2092062410.actionPerformed(Unknown Source)
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.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.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$400(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)
무엇 문제가 발생했습니다. 내가 배경 스레드로 메서드를 옮겼을 때 효과적 이었지만 EDT에서 대화 상자 GUI를 만들고 싶지 않았기 때문에이 메서드를 사용하고 싶지 않습니다.
//Creates compilation error
private class ConfigureDatabase extends SwingWorker<Void, String[]>
{
private CredentialEditor instance;
public ConfigureDatabase()
{ //Runs on EDT
this.instance = CredentialEditor.promptPossibleDialog(true);
}
@Override
protected Void doInBackground()
{ //Runs in background thread
try(Database database = CredentialEditor.getCredentials(instance))
{
//code
}
}
}
문제
//Runs just fine, but dialog GUI is not on EDT
private class ConfigureDatabase extends SwingWorker<Void, String[]>
{
@Override
protected Void doInBackground()
{ //Runs in background thread
try(Database database = CredentialEditor.getCredentials(CredentialEditor.promptPossibleDialog(true)))
{
//code
}
}
}
방법 대 :
public static CredentialEditor promptPossibleDialog(boolean reset)
{
if(reset || ConnectionPool.getInstance() == null)
{ //Checks to see if a dialog box needs to be created.
if(SwingUtilities.isEventDispatchThread())
{ //Checks to make sure the thread is on the EDT.
return new CredentialEditor();
}
else
{ //If it's not on the EDT throw an exception warning.
throw new IllegalStateException("Must run on EDT!");
}
}
return null; //If no dialog box needs to be created return nothing.
}
은 단순히 방법이 문제가 발생를 호출하는 것 같다 문제에 대한 자세한한다. 인스턴스 변수 나 메서드 안의 어떤 것도 설정하지 않고 있습니다. 이것은 단지 EDT에서 정적 메서드를 호출하는 것입니다. 사실, 그것은 단순히 같이 방법을 알리는 것 라인에 스택 트레이스 포인트가
그래서 무슨 일이 오류의 원인이되고 공공 정적 CredentialEditor promptPossibleDialog (부울 재설정)라는 라인이 경우 그럴 수 없어 주위에 그것을 얻을 방법에 대한 내 GUI 코드를 실행할 수 있습니다 EDT에 대한 경우에도 백그라운드 스레드에서 호출되고있다?
@VinceEmigh 그의 게시물에서 가장 먼저 다루는 것들 중 하나입니다 :'Unresolved compilation problem ' –
'CredentialEditor' 클래스의 나머지 코드를 볼 수 있습니까? –
@VinceEmigh 그것이 저에게이 문제를 흥미롭게 만듭니다 :) 그의 컴파일러는 정확히 어떤 오류를 말하지 않습니다. 컴파일 오류가 있다고합니다. –