Win a copy of Node.js Design Patterns: Design and implement production-grade Node.js applications using proven patterns and techniques this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Sublist

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 9105
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How have you considered approaching the problem?
 
Garion Winters
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
(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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 7023
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9105
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
*smacks himself*
Oh, I see. Thank you very much. Helped out a bundle!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic