null pointer returned when accessing viewManager.getNodeView()

25 views
Skip to first unread message

M P

unread,
Sep 12, 2018, 11:47:25 PM9/12/18
to cytoscape-helpdesk
Per title my view manager is returning null objects when requesting the View<> object equivalent of either CyNode or CyEdge. Here's my setup:

        network = networkFactory.createNetwork();
        network
.getRow(network).set(CyNetwork.NAME, "Results");
       
       
CyNetworkView view = viewFactory.createNetworkView(network);

       
...

       
CyNode cy = network.addNode(); // Works
   
        network
.getRow(cy).set(CyNetwork.NAME, name); // Works
        cynodes
.put(name, cy); // Works
               
       
View<CyNode> nodeDesign = view.getNodeView(cy); // nodeDesign is null!
        nodeDesign
.setVisualProperty(BasicVisualLexicon.NODE_FILL_COLOR, Color.YELLOW); // null pointer exception thrown!


Scooter Morris

unread,
Sep 13, 2018, 10:59:41 AM9/13/18
to cytoscape-helpdesk
Hi M P,
   This sometimes happens as a result of Cytoscape's internal event mechanism.  See if explicitly calling flushPayloadEvents helps.  You'll need to get the CyEventHelper service first:

CyEventHelper helper = getService(CyEventHelper.class);

Then add:

helper.flushPayloadEvents();

right before your geNodeView(cy)...

-- scooter

M P

unread,
Sep 13, 2018, 1:12:36 PM9/13/18
to cytoscape-helpdesk
 This seemed to forever block a thread I was running from. I handle the calculations of a network in a worker thread and then invoke a callback function to display when the results are done. Here's my setup

// Callback from CyActivatorCalculationResponseThread.run()
   
public void handleResults(Results results) {
       
// Create a result model
       
CyResultModel model = null; // Custom class that connects nodes to edges and modifies the visual of those nodes
       
       
if(results != null) {
           
CyNetworkViewFactory viewFactory = getService(bc, CyNetworkViewFactory.class);
           
CyNetworkViewManager viewManager = getService(bc, CyNetworkViewManager.class);
           
CyEventHelper helper             = getService(bc, CyEventHelper.class);
            helper
.flushPayloadEvents(); // Adding this has blocked the thread as it never finishes
            model
= new CyResultModel(networkFactory, viewFactory, viewManager, results);
           
           
// add network to cytoscape
           
CyNetworkManager networkManager = getService(bc, CyNetworkManager.class);

           
// ========>> We never get here anymore!
            networkManager
.addNetwork(model.getNetwork());
       
}
       
       
// Log status
       
int numResults = 0;
       
int numEvents = 0;
       
       
if(results != null) {
            numResults
= results.getResultCount();
           
           
for(int i = 0; i < numResults; i++) {
                numEvents
+= results.getResult(i).getEventCount();
           
}
       
}
       
       
this.AddLog("Returned " + numResults + " subnetworks, " + numEvents + " nodes\n");
   
        runButtonRef
.setEnabled(true);;
        connectButtonRef
.setEnabled(true);
        runButtonRef
.setText(originalRunText);
   
}


M P

unread,
Sep 25, 2018, 4:06:06 PM9/25/18
to cytoscape-helpdesk
bump

M P

unread,
Oct 4, 2018, 7:31:09 PM10/4/18
to cytoscape-helpdesk
hello still no help

M P

unread,
Oct 10, 2018, 1:35:15 PM10/10/18
to cytoscape-helpdesk
Scooter's offered solution blocks the thread it is called in. Is this a bug in cytoscape?

David Otasek

unread,
Oct 11, 2018, 3:08:39 PM10/11/18
to cytoscape-helpdesk
Have you tried running this on the Event Dispatch Thread using SwingUtilities.invokeLater()?

M P

unread,
Oct 11, 2018, 3:22:22 PM10/11/18
to cytoscape...@googlegroups.com
No I have not. I've been using Future Tasks. I will try that and report back. Thank you so much for the lead. I felt like I was at a dead end.

--
You received this message because you are subscribed to a topic in the Google Groups "cytoscape-helpdesk" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cytoscape-helpdesk/VYUAYcrcBzY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cytoscape-helpd...@googlegroups.com.
To post to this group, send email to cytoscape...@googlegroups.com.
Visit this group at https://groups.google.com/group/cytoscape-helpdesk.
To view this discussion on the web visit https://groups.google.com/d/msgid/cytoscape-helpdesk/2dbc2e02-167e-4599-89df-6e81418a7d4e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages