Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » Problem in loading emf model when opening
Problem in loading emf model when opening [message #191352] Tue, 09 August 2005 22:50 Go to next message
Yong cheng is currently offline Yong chengFriend
Messages: 46
Registered: July 2009
Member
Hallo, GEF experts,

I've already spent a whole night on looking for the bugs. I could not
understand what is the reason for the java.lang.ClassCastException while
loading the emf model. Error was caused by following code in "setInput":

URI fileURI=URI.createURI(file.getFullPath().toString());
Resource resource = new XMLResourceImpl(fileURI);
try {
resource.load(null);
model = (Model)resource.getContents().get(0);
//java.lang.ClassCastException
} catch (IOException e) {
model = ModelFactory.eINSTANCE.createModel();
resource.getContents().add(model);
}

As long as I create one model though wizard, in which

IDE.openEditor(page, newFile, true);

was called. The model can be loaded again.

Can someone help me to find the bug?

Thanks

Lucia
Problem solved!! [message #191368 is a reply to message #191352] Tue, 09 August 2005 23:24 Go to previous messageGo to next message
Yong cheng is currently offline Yong chengFriend
Messages: 46
Registered: July 2009
Member
I found the solution !

The following code should be used

(1)EList l = resource.getContents();
Iterator i = l.iterator();
while (i.hasNext()) {
Object o = i.next();
if (o instanceof Model)
model = (Model) o;
}

instead of

(2)model = (Model)resource.getContents().get(0);

I still have no idea, why the second one is not correct. During the debug
I can exactly see that the resource has only one element in his content,
which is one instance of Model.

Any reasonable explaination is still welcome!!!
Re: Problem solved!! [message #191529 is a reply to message #191368] Wed, 10 August 2005 16:59 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: none.unknown.com

Most likely you were doing something wrong. But a better place for this
question would be the EMF newsgroup.

"Lucia" <cheng_lucia@yahoo.com> wrote in message
news:1463023ae45f3770a6961eda4826e773$1@www.eclipse.org...
> I found the solution !
>
> The following code should be used
>
> (1)EList l = resource.getContents();
> Iterator i = l.iterator();
> while (i.hasNext()) {
> Object o = i.next();
> if (o instanceof Model)
> model = (Model) o;
> }
>
> instead of
>
> (2)model = (Model)resource.getContents().get(0);
>
> I still have no idea, why the second one is not correct. During the debug
> I can exactly see that the resource has only one element in his content,
> which is one instance of Model.
>
> Any reasonable explaination is still welcome!!!
>
Re: Problem solved!! [message #192083 is a reply to message #191529] Sun, 14 August 2005 11:46 Go to previous message
Eclipse UserFriend
Originally posted by: siegercn.cs.tu-berlin.de

hi,
have you tryed to change from
model = (Model)resource.getContents().get(0),
to
model = (Model)(resource.getContents().get(0));

Yang

Pratik Shah wrote:
> Most likely you were doing something wrong. But a better place for this
> question would be the EMF newsgroup.
>
> "Lucia" <cheng_lucia@yahoo.com> wrote in message
> news:1463023ae45f3770a6961eda4826e773$1@www.eclipse.org...
>
>>I found the solution !
>>
>>The following code should be used
>>
>> (1)EList l = resource.getContents();
>> Iterator i = l.iterator();
>> while (i.hasNext()) {
>> Object o = i.next();
>> if (o instanceof Model)
>> model = (Model) o;
>> }
>>
>>instead of
>>
>> (2)model = (Model)resource.getContents().get(0);

>>
>>I still have no idea, why the second one is not correct. During the debug
>>I can exactly see that the resource has only one element in his content,
>>which is one instance of Model.
>>
>>Any reasonable explaination is still welcome!!!
>>
>
>
>
Previous Topic:GEF with EMF (HELP!!!)
Next Topic:model with no visual information
Goto Forum:
  


Current Time: Thu Apr 25 19:35:05 GMT 2024

Powered by FUDForum. Page generated in 0.03488 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top