そのオブジェクトを作成せずに拡張機能をロードしようとしています。
残念ながら、アプリケーションを起動するとClassNotFoundExceptionが発生します。
なぜ私のクラスを見つけられないのか分かりません。これを修正する方法はありますか?
XMLドキュメントの一部。ラベルは私のクラスです:
<Label>Hauptteil</Label>
<Fields>
<Field id="main.text" type="text">
<Label>Text</Label>
</Field>
<Field id="main.multilinetext" type="multilinetext">
<Label>mehrzeiliger Text</Label>
</Field>
<Field id="main.negativnumber" type="number">
<Label>Zahl</Label>
</Field>
<Field id="main.positivenumber" type="positivenumber">
<Label>positive Zahl</Label>
</Field>
<Field id="main.negativnumber" type="negativnumber">
<Label>negative Zahl</Label>
</Field>
<Field id="main.negativnumber" type="image">
<Label>Bild</Label>
</Field>
</Fields>
</Node>
それは私のクラスをロードするための私のコードです:
public void execute() {
IExtensionRegistry registry = Platform.getExtensionRegistry();
IConfigurationElement[] config = registry.getConfigurationElementsFor(FIELDWIDGET_ID);
for (IConfigurationElement configElement : config) {
if (configElement.getAttribute("type") != null) {
System.out.println(configElement.getAttribute("type"));
String pluginId = configElement.getContributor().getName();
Bundle bundle = Platform.getBundle(pluginId);
try {
Class<?> theClass = bundle.loadClass("class");
Constructor<?> con = configElement.getClass().getConstructor(Field.class, Composite.class);
hashMap.put(configElement.getAttribute("type"), con);
} catch (NoSuchMethodException | SecurityException | ClassNotFoundException e1) {
e1.printStackTrace();
}
}
}
}
class
構成要素から属性の値を取得し、そのクラスをロードしてから、そのクラスのコンストラクターにアクセスする必要があります。
だから交換
Class<?> theClass = bundle.loadClass("class");
Constructor<?> con = configElement.getClass().getConstructor(Field.class, Composite.class);
と
String className = configElement.getAttribute("class");
Class<?> theClass = bundle.loadClass(className);
Constructor<?> con = theClass.getConstructor(Field.class, Composite.class);
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加