Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » ContentProvider for TableViewer Problem
ContentProvider for TableViewer Problem [message #459861] Thu, 18 August 2005 16:20 Go to next message
James Leotta is currently offline James LeottaFriend
Messages: 203
Registered: July 2009
Senior Member
This return in the method within a ContentProvider

public Object[] getElements(Object inputElement) (
return inputElement.getCases().toArray();


needs to be replaced with something not using the parameter inputElement
like
return caseList.getCases().toArray();

because the method gets called before setInput is called causing a null
pointer exception. It would seem that the getElements method should not
be called until setInput is called. Am I missing something?
Re: ContentProvider for TableViewer Problem [message #459920 is a reply to message #459861] Thu, 18 August 2005 17:09 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: sunil_kamath.nohotspammail.com

"James Leotta" <jleotta@bascom.com> wrote in message
news:de2cds$mhv$1@news.eclipse.org...
> This return in the method within a ContentProvider
>
> public Object[] getElements(Object inputElement) (
> return inputElement.getCases().toArray();
>
>
> needs to be replaced with something not using the parameter inputElement
> like
> return caseList.getCases().toArray();
>
> because the method gets called before setInput is called causing a null
> pointer exception. It would seem that the getElements method should not
> be called until setInput is called. Am I missing something?

Yes you are.
You should check for nulls in the getElements() method.
If inputElement == null, then return null.
---
Sunil
Re: ContentProvider for TableViewer Problem [message #459926 is a reply to message #459861] Thu, 18 August 2005 21:48 Go to previous messageGo to next message
Chris is currently offline ChrisFriend
Messages: 17
Registered: July 2009
Junior Member
James Leotta wrote:

> This return in the method within a ContentProvider

> public Object[] getElements(Object inputElement) (
> return inputElement.getCases().toArray();


> needs to be replaced with something not using the parameter inputElement
> like
> return caseList.getCases().toArray();

> because the method gets called before setInput is called causing a null
> pointer exception. It would seem that the getElements method should not
> be called until setInput is called. Am I missing something?

Here is how the ArrayContentProvider does it:

public Object[] getElements(Object inputElement) {
if (inputElement instanceof Object[])
return (Object[]) inputElement;
if (inputElement instanceof Collection)
return ((Collection) inputElement).toArray();
return new Object[0];
}

So effectively you should be adding null checks.
Re: ContentProvider for TableViewer Problem [message #459941 is a reply to message #459861] Fri, 19 August 2005 19:20 Go to previous message
James Leotta is currently offline James LeottaFriend
Messages: 203
Registered: July 2009
Senior Member
Thanks folks!

James Leotta wrote:
> This return in the method within a ContentProvider
>
> public Object[] getElements(Object inputElement) (
> return inputElement.getCases().toArray();
>
>
> needs to be replaced with something not using the parameter inputElement
> like
> return caseList.getCases().toArray();
>
> because the method gets called before setInput is called causing a null
> pointer exception. It would seem that the getElements method should not
> be called until setInput is called. Am I missing something?
Previous Topic:Fixed Editor - How to avoid the user to close one editor
Next Topic:JFace Document
Goto Forum:
  


Current Time: Wed Nov 26 08:12:47 GMT 2014

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

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