odoe

Porting a Network trace C# tool to Java.

Discussion created by odoe on Feb 10, 2011
Latest reply on May 16, 2012 by ldonahue
I'm diving head first into learning some Java using ArcObjects.
We have a Flow trace tool using a geometric network that we have written in C# and it works perfectly on the desktop and on server.

I have had some pretty good success in porting most of the code over to Java, but I have hit a snag in trying to cast a FeatureDataset to a NetworkCollection.

This is the working portion in C#.
// Obtain a reference to the geometric network in the feature workspace
IFeatureDataset featureDataset = featureWorkspace.OpenFeatureDataset("sde.Sewerage_Network_Classes");
INetworkCollection networkCollection = (INetworkCollection)featureDataset;
IGeometricNetwork geometricNetwork = networkCollection.get_GeometricNetworkByName("sde.Sewerage_Network_Classes_Net");

INetwork network = geometricNetwork.Network;


Looks pretty much the exact same in Java
// Obtain a reference to the geometric network in the feature workspace
INetwork network = null;
INetSolver netSolver = null;
IGeometricNetwork geometricNetwork = null;
INetworkCollection networkCollection = null;
try
{
 IFeatureDataset featureDataset = featureWorkspace.openFeatureDataset("sde.Sewerage_Network_Classes");
 networkCollection = (INetworkCollection) featureDataset; // <-- this is where the error happens
 geometricNetwork = networkCollection.getGeometricNetworkByName("sde.Sewerage_Network_Classes_Net");
}
catch(Exception e) 
{
 System.out.println("This error sucks!");
 System.out.println(e.getMessage());
}


I'm running my jUnit tests and catching the following error at the line indicated above.
com.esri.arcgis.geodatabase.IFeatureDatasetProxy cannot be cast to com.esri.arcgis.geodatabase.INetworkCollection


I'm using the same connection properties to connect to the SDE, using the default instance.
I'm pretty much stumped at this point. Is there a nuance that I might be missing?

Thanks in advance.

Outcomes