Life is but a BREATH
Randy Tong wrote:Have you initialized array b ?
Life is but a BREATH
Randy Tong wrote:Can you post more code here ?
Life is but a BREATH
Randy Tong wrote:Of course you can
Campbell Ritchie wrote:Welcome to the Ranch
Randy is correct. You have created the array but you haven't filled it. Until such time as you fill it, it contains . . . . well, try it.
No, you didn't; System.out.println won't throw that sort of exception.Celt Shady wrote:. . . i encountered the same error
Campbell Ritchie wrote:
No, you didn't; System.out.println won't throw that sort of exception.Celt Shady wrote:. . . i encountered the same error
Campbell Ritchie wrote:Apology accepted
You only need to print one of those arrays like that to see the problem; what did it print?
Campbell Ritchie wrote:That is normal; look in the Java® Language Specification (=JLS) here. Until you have replaced the elements with something 𠀜real”, they have the default value of null. You are going to have to replace the nulls: Students[999] = new Student(...); There are more elegant ways to do it without writing that sort of thing 100×.
If your array is partially filled, you will have to avoid uusing those elements still null.
Celt Shady wrote:should i post my Student,subject and schedule classes?
Life is but a BREATH
Randy Tong wrote:
Celt Shady wrote:should i post my Student,subject and schedule classes?
Yes, please read How to Ask Questions On Java Ranch
Life is but a BREATH
Life is but a BREATH
Randy Tong wrote:Also, what is count++; (at line 64) used for ?
For below code, shouldn't it be units2 instead of units 1 ?
Life is but a BREATH
Randy Tong wrote:Yes. At first it setCode to a[0]
But after count++, you get the code for a[1].
So what would you expect it to be printed ?
Life is but a BREATH
Celt Shady wrote:
it only print the first 2 outputs
Student id:
Student name:
Life is but a BREATH
so do i need to remove all count++?Randy Tong wrote:
Celt Shady wrote:
it only print the first 2 outputs
Student id:
Student name:
NO. With count ++, you will get null pointer ERROR.
Life is but a BREATH
Randy Tong wrote:Please kindly explain how your application should work
Life is but a BREATH
oh i see i'll edit them and lets sed thanks for your help thoRandy Tong wrote:In case1 , you use count, case2 use count2 and case3 use count3. But when you print out get method, you only use count. That is wrong.
Celt Shady wrote:oh i see i'll edit them and lets sed thanks for your help tho
Life is but a BREATH
You also mixed up the count.Celt Shady wrote:What's wrong with that code?
Life is but a BREATH
Randy Tong wrote:
You also mixed up the count.Celt Shady wrote:What's wrong with that code?
What's that smell? I think this tiny ad may have stepped in something.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|