Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

output prints null

 
Nich Kud
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
been working on this program for awhile now and part of the output is only printing null so very tired, was wondering if anyone knows how to fix my error.

 
Paul Clapham
Sheriff
Posts: 21149
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nich Kud wrote:part of the output is only printing null


Which part is that?
 
Nich Kud
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
Nich Kud wrote:part of the output is only printing null


Which part is that?



on line 89, it only outputs the last input the user does.
 
Victor Ewert
Greenhorn
Posts: 17
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing you are using arrays to track the information, for each time a user adds another item. Part of the problem is, in lines 66 to 75, you keep creating new arrays to add things to which means you are losing the data from the previous iterations. I believe that is why, on line 89 you are only getting the last result.

I see what you are trying to do in lines 66 to 75 is re-adjust the size of the array, since at the beginning of the program you don't know how big the array should be. Instead of using arrays use the ArrayList class which is a List that expands as needed.

Hope that helps,
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic