gpt4 book ai didi

java - Jface:Listviewer 抛出 AssertionFailedException

转载 作者:行者123 更新时间:2023-12-01 13:45:49 25 4
gpt4 key购买 nike

我想创建一个 Jface Listviewer,但它总是抛出以下异常:

 org.eclipse.core.runtime.AssertionFailedException: assertion failed: 
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:110)
at org.eclipse.core.runtime.Assert.isTrue(Assert.java:96)
at org.eclipse.jface.viewers.StructuredViewer.assertContentProviderType(StructuredViewer.java:1671)
at org.eclipse.jface.viewers.StructuredViewer.setContentProvider(StructuredViewer.java:1661)
at property.sheet.internalConstraint.ConstraintDialog.createDialogArea(ConstraintDialog.java:26)
at org.eclipse.jface.dialogs.Dialog.createContents(Dialog.java:775)
at org.eclipse.jface.window.Window.create(Window.java:432)
at org.eclipse.jface.dialogs.Dialog.create(Dialog.java:1104)
at org.eclipse.jface.window.Window.open(Window.java:791)
....

我的 createDialogArea 方法(我在其中创建 ListViewer)如下所示:

protected Control createDialogArea(Composite parent) {
Composite container = (Composite) super.createDialogArea(parent);
lv = new ListViewer(container, SWT.SINGLE);
lv.setContentProvider(new ConstraintDialogContentProvider());
lv.setLabelProvider(new ConstraintDialogLabelProvider());
lv.setInput(fm);
return container;
}

通过调试,发现在我设置contentProvider后抛出异常:

public class ConstraintDialogContentProvider implements IContentProvider {

private List<Feature> features = new ArrayList<Feature>();

@Override
public void dispose() {
}

@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}

public Object[] getElements(Object input) {
if (input instanceof FeatureMap) {
FeatureMap fm = (FeatureMap) input;
if (fm.getFeature() != null) {
getAllFeatures(fm.getFeature());
return features.toArray();
} else {
return null;
}
}
return null;
}

private void getAllFeatures(Feature feature) {
features.add(feature);
.....
// adds additional features
}
}

我真的不明白我在这里做错了什么。有什么想法吗?

干杯,菲尔

最佳答案

ListViewer 的内容提供程序必须实现 IStructuredContentProvider 而不仅仅是 IContentProviderassertContentProviderType 调用正在检查这一点。

关于java - Jface:Listviewer 抛出 AssertionFailedException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20385486/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com