First, I would like to thank members who sent me inputs via email. I
especially followed an example given by one. Now it works.

I will describe here briefly. The standard sort() does not handle null
instance. However, there is an overloaded version that takes a
comparator. Therefore, we can pass our own comparator to sort(). Like:
// Standard sort. Causes NullPointerException when there are null
instances in the argument:array.
Arrays.sort(objects);
// An oveloaded sort. Pass a comparator that handles null instances.
Arrays.sort(objects, comparator);

>
> Can you please provide the code.
>
> Nirmal
> o00o oOOo
>                 \\\/
>              /         \
>              | \\   // |
>            ( | (.) (.) |)
> ----------o00o--(_)--o00o-------------------
> Stand up,be bold,be strong.
> Take the whole responsibility on
> ur own shoulders and know that
> U are the creator of ur own destiny.
> ------ooo0-------------------------------------
>    (   )     0ooo
>     \ (      (   )
>      \_)      ) /
>              (_/
>
> On Wed, Jul 1, 2009 at 10:22 PM, * ^ * <[email protected]> wrote:
>
>
>
>
>
> > I have an array of comparable objects. Applying Arrays.sort() on it
> > causes a NullPointerException. Relevant code:
> >    public void remove(int index){
> >        // objects contain null too. Like: {object, object, null,
> > null}
> >        objects[index]=null;
> >        // Next statement causes a NullPointerException. I suspect the
> > null references causing this.
> >        Arrays.sort(objects);
> >        pointer--;
> >    }
>
> > Any idea how I can overcome this? Do let me know if require more codes
> > and details. Thank you.

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/javaprogrammingwithpassion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to