|
|
|
Re: File Not Found error on loading calling getResource [message #868512 is a reply to message #868167] |
Wed, 02 May 2012 05:56 |
Ed Merks Messages: 33216 Registered: July 2009 |
Senior Member |
|
|
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Josef,<br>
<br>
Comments below.<br>
<br>
On 01/05/2012 7:28 PM, Josef Pohl wrote:
<blockquote cite="mid:jnp6fm$gj0$1@xxxxxxxxe.org" type="cite">Hi
there, This problem may have a very easy solution and I am just
missing it. I have dug around a bit but have not found any
pertinent information. <br>
I am getting a FileNotFoundException on trying to load get a
resource from a file.
<br>
</blockquote>
No doubt because you're accessing the file system directly and the
file isn't there.<br>
<blockquote cite="mid:jnp6fm$gj0$1@xxxxxxxxe.org" type="cite">I
am using the Graphiti framework to create diagrams. I separate my
diagram from my model files. What I am trying to do is gather a
collection of diagrams to one of which I will associate a model
element. <br>
</blockquote>
Most likely you should be using URIs refer to the workspace...<br>
<blockquote cite="mid:jnp6fm$gj0$1@xxxxxxxxe.org" type="cite">The
stack trace I am getting is: <br>
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl$1DiagnosticWrappedException:
java.io.FileNotFoundException:
/egsc_test3/src/diagrams/Test47.diagram (No such file or
directory)
<br>
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.handleDemandLoadException(ResourceSetImpl.java:315)<br>
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)<br>
at
org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:397)<br>
at utils.FileUtil.getDiagramFromFile(FileUtil.java:88)
<br>
at utils.FileUtil.getDiagrams(FileUtil.java:32)
<br>
at
features.EgsndiagramDrillDownGoalFeature.getDiagrams(EgsndiagramDrillDownGoalFeature.java:60)<br>
at
org.eclipse.graphiti.ui.features.AbstractDrillDownFeature.getLinkedDiagrams(AbstractDrillDownFeature.java:183)<br>
at
org.eclipse.graphiti.ui.features.AbstractDrillDownFeature.canExecute(AbstractDrillDownFeature.java:150)<br>
at
features.EgsndiagramDrillDownGoalFeature.canExecute(EgsndiagramDrillDownGoalFeature.java:42)<br>
at
org.eclipse.graphiti.ui.internal.action.CustomAction.isEnabled(CustomAction.java:51)<br>
at
org.eclipse.jface.action.ActionContributionItem.update(ActionContributionItem.java:946)<br>
at
org.eclipse.jface.action.ActionContributionItem.fill(ActionContributionItem.java:291)<br>
...
<br>
<br>
Above, /egsc_test3 is the project. Test47.diagram is the diagram
file I am trying to load. <br>
The error is derived from this function (On the line marked ERROR
FROM HERE):
<br>
<br>
private static Diagram getDiagramFromFile(IFile file,
ResourceSet resourceSet) {
<br>
// Get the URI of the model file.
<br>
final URI resourceURI = getFileURI(file, resourceSet);
<br>
</blockquote>
What does getFileURI do? Anything like this?<br>
<blockquote><a style=""
href="http://wiki.eclipse.org/index.php/EMF/FAQ#How_do_I_map_between_an_EMF_Resource_and_an_Eclipse_IFile.3F"><span
class="tocnumber">2.44</span> <span class="toctext">How do I
map between an EMF Resource and an Eclipse IFile?</span></a><br>
</blockquote>
<blockquote cite="mid:jnp6fm$gj0$1@xxxxxxxxe.org" type="cite">
<br>
// Demand load the resource for this file.
<br>
Resource resource;
<br>
try {
<br>
resource = resourceSet.getResource(resourceURI, true);
// ERROR FROM HERE
<br>
if (resource != null) {
<br>
// does resource contain a diagram as root object?
<br>
final EList<EObject> contents =
resource.getContents();
<br>
for (final EObject object : contents) {
<br>
if (object instanceof Diagram) {
<br>
return (Diagram) object;
<br>
}
<br>
}
<br>
}
<br>
} catch (final WrappedException e) {
<br>
e.printStackTrace();
<br>
}
<br>
<br>
return null;
<br>
}
<br>
<br>
<br>
I have tried both loading the model file (which has an extension
".egsn") and the diagram file (extension ".diagram"). Both derive
the same result. <br>
The resourceSet that is passed in at that point is empty. (But it
is not clear to me that it needs to have any contents.)</blockquote>
It generally starts out empty.<br>
<blockquote cite="mid:jnp6fm$gj0$1@xxxxxxxxe.org" type="cite">
The resourceURI contains: File String:
/egsc_test3/src/diagrams/Test47.diagram
<br>
</blockquote>
So you're not using platform:/resource/<project-name> as you
should.<br>
<blockquote cite="mid:jnp6fm$gj0$1@xxxxxxxxe.org" type="cite">
<br>
The relative path is OK and is derived from searching the project
resources, hence the file does exist. <br>
</blockquote>
But not at that location in the file system. You should be sure to
always use an absolute URI, i.e., one with a scheme such as file:,
platform:, or http:<br>
<blockquote cite="mid:jnp6fm$gj0$1@xxxxxxxxe.org" type="cite">Does
anyone have any thoughts on why getResource might be throwing this
exception?
<br>
<br>
Thanks in advance. If I can clarify anything or provide any extra
information please feel free to ask.
<br>
</blockquote>
I'm sure reading the FAQ link above will clarify the situation.<br>
<blockquote cite="mid:jnp6fm$gj0$1@xxxxxxxxe.org" type="cite">
<br>
All my best,
<br>
Joe
<br>
<br>
</blockquote>
</body>
</html>
Ed Merks
Professional Support: https://www.macromodeling.com/
|
|
|
|
Powered by
FUDForum. Page generated in 0.04501 seconds