Results 21 to 29 of 29
- 11-07-2012, 04:35 PM #21
Senior Member
- Join Date
- Jul 2012
- Posts
- 165
- Rep Power
- 1
Re: How can I count "trues" in an array?
done research again :)
If I am trying to use null values instead of an object.
is there something wrong with the arrays I am creating?
if I use this code:
Will it be creating an array called A, with type AtoCSeat, that is 14 long and contains 14 instances of the AtoCSeat? (i.e. A1 is new AtoCSeat, A2 is another...).Java Code:static AtoCSeat[] A; A = new AtoCSeat[14];
Or, has it just created 14 variables of type AtoCSeat which are still null?
Hence I still need to initialise each of these array variables with instanced of AtoCSeat?Last edited by kkid; 11-07-2012 at 04:45 PM.
- 11-07-2012, 05:00 PM #22
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: How can I count "trues" in an array?
They're all null by default.
Please do not ask for code as refusal often offends.
- 11-07-2012, 05:13 PM #23
Senior Member
- Join Date
- Jul 2012
- Posts
- 165
- Rep Power
- 1
Re: How can I count "trues" in an array?
At least we're making progress :)
I have now tried initialising all of the array variables by creating a method called theatreInitialisation which used a while loop to assign "new AtoCSeat()" to them (Or DtoFSeat etc...).
I then added this method to run after the theatreCreation (array creation) in main.
The problem now is that the program will not run, I don't think my UI method ever gets ran for some reason.
The program compiles perfectly fine but gives no output whatsoever and will not terminate.
The code I added (have I caused an infinite loop?)
Java Code:public static void theatreInitialisation(){ int index = 0; while (index < A.length) { A[0] = new AtoCSeat(); } index = 0; while (index < B.length) { B[0] = new AtoCSeat(); } index = 0; while (index < C.length) { C[0] = new AtoCSeat(); }index = 0; while (index < D.length) { D[0] = new DtoFSeat(); } index = 0; while (index < E.length) { E[0] = new DtoFSeat(); } index = 0; while (index < F.length) { F[0] = new DtoFSeat(); } index = 0; while (index < G.length) { G[0] = new GtoLSeat(); } index = 0; while (index < H.length) { H[0] = new GtoLSeat(); } index = 0; while (index < J.length) { J[0] = new GtoLSeat(); } index = 0; while (index < K.length) { K[0] = new GtoLSeat(); } index = 0; while (index < L.length) { L[0] = new GtoLSeat(); } }
EDIT: I forgot to increment index!
- 11-07-2012, 05:16 PM #24
Senior Member
- Join Date
- Jul 2012
- Posts
- 165
- Rep Power
- 1
Re: How can I count "trues" in an array?
ok, so that didn't work, back to the nullPointerException again
- 11-07-2012, 05:38 PM #25
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: How can I count "trues" in an array?
So what's null now?
Please do not ask for code as refusal often offends.
- 11-07-2012, 05:40 PM #26
Senior Member
- Join Date
- Jul 2012
- Posts
- 165
- Rep Power
- 1
Re: How can I count "trues" in an array?
I think I've worked it out, I didn't put index in the square brackets when initialising.
Sorry about all of the posts, I have just been posting as I have been going along.
It was the exact same null exception as I hadn't been initialising all of the variables.
Hopefully it will work once add index to the brackets.
- 11-07-2012, 05:44 PM #27
Senior Member
- Join Date
- Jul 2012
- Posts
- 165
- Rep Power
- 1
Re: How can I count "trues" in an array?

IT FINALLY WORKS!
Thank you everybody who helped me with this, I am extremely grateful.
It was just me having lots of tiny stupid mistakes causing all the trouble.
- 11-07-2012, 05:46 PM #28
Moderator
- Join Date
- Apr 2009
- Posts
- 10,438
- Rep Power
- 16
Re: How can I count "trues" in an array?
It's a nice feeling, isn't it?
:)Please do not ask for code as refusal often offends.
- 11-07-2012, 05:51 PM #29
Senior Member
- Join Date
- Jul 2012
- Posts
- 165
- Rep Power
- 1
Similar Threads
-
Convert string operation symbols "+", "-", "/", "*" etc.
By Googol in forum New To JavaReplies: 3Last Post: 10-30-2012, 03:06 PM -
URLConnection -- does it count as a "click"?
By SnakeDoc in forum NetworkingReplies: 5Last Post: 05-29-2012, 04:35 PM -
loop "play again" in an 8 ball game , loops but wont let me answer my "out.print"
By IareSmart in forum New To JavaReplies: 1Last Post: 02-01-2012, 08:37 PM -
Count lines cointaining "word" in input file
By gwithey in forum New To JavaReplies: 5Last Post: 04-02-2009, 05:23 AM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks