aspose file tools*
The moose likes Beginning Java and the fly likes Sublist Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Sublist" Watch "Sublist" New topic
Author

Sublist

Garion Winters
Greenhorn

Joined: Oct 01, 2002
Posts: 20
Hi there. I was wondering if anyone could help me out here... We are currently doing a project that involves creating a new class called sublist. This takes params of (MyList list, int startIndex, int endIndex). It is basically a partial view of the list (MyList is used because we have been making our own). I'm not looking for an answer, just help here.
We are not to change that constructor, and if you edit anything about the sublist, it should change the actual list. (IOW if you look from the 3rd object to the 5th, and add a new one, it should be so in the original, non-sub list as well)
Any help would be appreciated.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
Have you seen the way that sublist was implemented in the API? List

You can see the source code by looking in (java_home)/src after you unjar src.jar or src.zip (depending on whether you're using 1.3 or 1.4)
[ October 14, 2002: Message edited by: Marilyn de Queiroz ]

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
How have you considered approaching the problem?


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Garion Winters
Greenhorn

Joined: Oct 01, 2002
Posts: 20
(Sorry for the delay.. networking troubles)
Well, I have thought about basically extending our class, MyAbstractList, then for the constructor, make a new MyList by iterating through the startIndex and endIndex and add it to the new MyList. Of course, now I am having all null pointer exceptions (We have 10 test cases... all fail at the same point in the constructor)
Here is what I have. Any help would be great Thx again.
BTW... we can't change the constructor params.
The MySubList (what we are writing)

The MyAbstractList (that I extended)

And the MyList...

If you need to see any other files, let me know. We made a lot over the time, but those are the ones I can see as important. Can't get over the nulls...
Garion Winters
Greenhorn

Joined: Oct 01, 2002
Posts: 20
Hmm.. I wrote like 170 or so lines of code now, and that one part is STILL causing me errors... I tried adding a while hasNext part, to make sure there is a next before going on, but the test cases all still reveal a NULL POINTER EXCEPTION ERROR! ... here is where I am having the trouble

Silly thing is driving me nuts. Any suggestions?
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
You're getting a NullPointerException because you never initialize your sublist to be something other than null. In other words, you never say MyList sublist = new MyList() ;
Garion Winters
Greenhorn

Joined: Oct 01, 2002
Posts: 20
That is what I thought... but everytime I tried to do that, it says I can't. MyList is an interface, and it won't allow me to initialize it so. Hmmmm =(
I figure looking at the code they have would help greatly... just can't seem to find it for some reason. Thx everyone!
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
Find src.jar or src.zip in your JAVA_HOME directory. (my latest one is in C:\J2SDK_Forte\jdk1.4.0 and the previous one was in C:\jdk1.3.1_02). Unjar/unzip it. Then you can see the source files.

MyList is an interface, and it won't allow me to initialize it so.

I suggest you create a class that implements the MyList interface
for example

class MyPartialList implements MyList
{
// stuff
}

Then you can have MyList sublist = new MyPartialList();
Garion Winters
Greenhorn

Joined: Oct 01, 2002
Posts: 20
*smacks himself*
Oh, I see. Thank you very much. Helped out a bundle!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sublist