Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

cattle drive exercise

 
Mike Gain
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I'm trying cattle drive exercise. Below is the code I write for assignment 5. I got a exeption said NullPointerException at line 6.
Can anybody tell me the problem?Thank you.
[ code removed -ds ]
[ September 30, 2002: Message edited by: Dirk Schreckmann ]
 
Wilfried LAURENT
Ranch Hand
Posts: 269
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You instanciate you array 'arr' with the following line:
[ code removed ]
Then you set values with:
[ code removed ]
but the second dimension of your array is never allocated.
You should write something like
[ code removed ]
if you want the same dimension for each row, or
[ code removed ]
if you want different size for each row.
W.
[ September 30, 2002: Message edited by: Dirk Schreckmann ]
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
pgup down,
Welcome to JavaRanch!
We ain't got many rules 'round these parts, but we do got one. Please change your display name to comply with The JavaRanch Naming Policy.
Thanks Pardner! Hope to see you 'round the Ranch!
-------------------------
Please do not post code related to Cattle Drive assignments. Also, please don't otherwise share solutions on the forum.
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got a exeption said NullPointerException
That must be because you were trying to improperly use an object reference that didn't yet refer to an object - it referred to null.
 
Mike Gain
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
display name changed.
 
Marilyn de Queiroz
Sheriff
Posts: 9063
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are more than welcome to go to the Cattle Drive forum and post a question. The only requirement is that you do not post code. You may, however, post pseudocode.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic