#java
На этот вопрос уже даны ответы здесь:
Что такое Null Pointer Exception и как его исправить?
(4 ответа)
Закрыт 2 года назад.
Есть код:
public class FunDep {
HashSet body;
HashSet head;
public FunDep(HashSet body, HashSet head) {
this.head = head;
this.body = body;
}
}
public static Object SetSortShapes(mxGraph var2) {
var2.selectCells(true, true);
Object[] var3 = var2.getSelectionCells();
ArrayList Entity_mas = new ArrayList<>();
ArrayList Relation_Mas = new ArrayList<>();
FunDep[] FunDepMas = new FunDep[200];
int FunDepMasCount = 0;
int EntityCounter = 0, RelationCounter = 0;
for (int i = 0; i < var3.length; ++i) {
if (var2.getModel().isVertex(var3[i]) == true) {
switch (var2.getModel().getStyle(var3[i])) {
case "fillColor=#289bfc":
Entity_mas.add(EntityCounter, var3[i]);
++EntityCounter;
break;
case "rhombus;fillColor=#fff312":
Relation_Mas.add(RelationCounter, var3[i]);
++RelationCounter;
break;
}
}
}
for (int i = 0; i < EntityCounter; ++i) //ищем пары ключевые-неключевые по сущностям
{
ArrayList keyAttr = new ArrayList<>();
ArrayList NotkeyAttr = new ArrayList<>();
int keyAttrCount = 0;
int NotkeyAttrCount = 0;
Object[] Entity_massiv = Entity_mas.toArray(new Object[Entity_mas.size()]);
Object[] edges_mass = var2.getEdges(Entity_massiv[i]);
Object[] vertex_mas = var2.getOpposites(edges_mass, Entity_massiv[i]);
if (vertex_mas.length > 1) //если кол-во элементов равно единице - зависимостей нет
{
for (int k = 0; k < vertex_mas.length; ++k) //закидываем атрибуты во
временные массивы
{
if (var2.getModel().getStyle(vertex_mas[k]).equals("ellipse;fillColor=#31eb47;fontStyle=4")
== true) {
keyAttr.add(keyAttrCount, vertex_mas[k]);
++keyAttrCount;
}
if (var2.getModel().getStyle(vertex_mas[k]).equals("ellipse;fillColor=#31eb47")
== true) {
NotkeyAttr.add(NotkeyAttrCount, vertex_mas[k]);
++NotkeyAttrCount;
}
}
if (keyAttrCount >= 1 && NotkeyAttrCount >= 1) {
Object[] keyAttr_mas = keyAttr.toArray(new Object[keyAttr.size()]);
Object[] NotkeyAttr_mas = NotkeyAttr.toArray(new Object[NotkeyAttr.size()]);
for (int a = 0; a < keyAttrCount; ++a) {
FunDepMas[FunDepMasCount].head.add(keyAttr_mas[a]);
for (int b = 0; b < NotkeyAttrCount; ++b) {
FunDepMas[FunDepMasCount].body.add(NotkeyAttr_mas[b]);
}
++FunDepMasCount;
}
}
}
}
return FunDepMas[0];
}
}
При попытке инициализации элемента массива FunDepMas выдаёт ошибку. Подозреваю, что
что-то с классом накосячил, только понять не могу, что.
Код ошибки:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
at com.mxgraph.examples.swing.editor.Normalize.SetSortShapes(Normalize.java:63)
at com.mxgraph.examples.swing.editor.EditorAboutFrame.(EditorAboutFrame.java:48)
at com.mxgraph.examples.swing.editor.BasicGraphEditor.about(BasicGraphEditor.java:679)
at com.mxgraph.examples.swing.editor.EditorMenuBar$3.actionPerformed(EditorMenuBar.java:170)
at java.desktop/javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1967)
at java.desktop/javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2308)
at java.desktop/javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:405)
at java.desktop/javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:262)
at java.desktop/javax.swing.AbstractButton.doClick(AbstractButton.java:369)
at java.desktop/javax.swing.plaf.basic.BasicMenuItemUI.doClick(BasicMenuItemUI.java:980)
at java.desktop/javax.swing.plaf.basic.BasicMenuItemUI$Handler.mouseReleased(BasicMenuItemUI.java:1024)
at java.desktop/java.awt.Component.processMouseEvent(Component.java:6578)
at java.desktop/javax.swing.JComponent.processMouseEvent(JComponent.java:3343)
at java.desktop/java.awt.Component.processEvent(Component.java:6343)
at java.desktop/java.awt.Container.processEvent(Container.java:2259)
at java.desktop/java.awt.Component.dispatchEventImpl(Component.java:4961)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2317)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4793)
at java.desktop/java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4904)
at java.desktop/java.awt.LightweightDispatcher.processMouseEvent(Container.java:4539)
at java.desktop/java.awt.LightweightDispatcher.dispatchEvent(Container.java:4480)
at java.desktop/java.awt.Container.dispatchEventImpl(Container.java:2303)
at java.desktop/java.awt.Window.dispatchEventImpl(Window.java:2758)
at java.desktop/java.awt.Component.dispatchEvent(Component.java:4793)
at java.desktop/java.awt.EventQueue.dispatchEventImpl(EventQueue.java:766)
at java.desktop/java.awt.EventQueue.access$500(EventQueue.java:97)
at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:717)
at java.desktop/java.awt.EventQueue$3.run(EventQueue.java:711)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:99)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:739)
at java.desktop/java.awt.EventQueue$4.run(EventQueue.java:737)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(ProtectionDomain.java:89)
at java.desktop/java.awt.EventQueue.dispatchEvent(EventQueue.java:736)
at java.desktop/java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:199)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:124)
at java.desktop/java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:113)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:109)
at java.desktop/java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:101)
at java.desktop/java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
Process finished with exit code 0
Ответы
Ответ 1 Добро пожаловать на StackOverflow.
Массив создали, а объекты в нем?
FunDep[] FunDepMas = new FunDep[200];
for (int i = 0; i < FunDepMas.length; ++i)
FunDepMas[i] = new FunDep(new HashSet(), new HashSet());
...
Комментариев нет:
Отправить комментарий