Page 2 of 2 FirstFirst 12
Results 21 to 29 of 29
  1. #21
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    240
    Rep Power
    3

    Default 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:

    Java Code:
    static AtoCSeat[] A;
    A = new AtoCSeat[14];
    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...).


    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.

  2. #22
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,002
    Rep Power
    20

    Default 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.

    ** This space for rent **

  3. #23
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    240
    Rep Power
    3

    Default Re: How can I count "trues" in an array?

    Quote Originally Posted by Tolls View Post
    They're all null by default.
    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!

  4. #24
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    240
    Rep Power
    3

    Default Re: How can I count "trues" in an array?

    ok, so that didn't work, back to the nullPointerException again

  5. #25
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,002
    Rep Power
    20

    Default Re: How can I count "trues" in an array?

    So what's null now?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  6. #26
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    240
    Rep Power
    3

    Default 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.

  7. #27
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    240
    Rep Power
    3

    Default 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.

  8. #28
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,002
    Rep Power
    20

    Default 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.

    ** This space for rent **

  9. #29
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    240
    Rep Power
    3

    Default Re: How can I count "trues" in an array?

    Quote Originally Posted by Tolls View Post
    It's a nice feeling, isn't it?
    :)
    It really is, I am completely new to programming, this is my first language and this program is my first project, therefore I haven't really had one of these feelings before :)

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Replies: 3
    Last Post: 10-30-2012, 03:06 PM
  2. URLConnection -- does it count as a "click"?
    By SnakeDoc in forum Networking
    Replies: 5
    Last Post: 05-29-2012, 04:35 PM
  3. Replies: 1
    Last Post: 02-01-2012, 08:37 PM
  4. Count lines cointaining "word" in input file
    By gwithey in forum New To Java
    Replies: 5
    Last Post: 04-02-2009, 05:23 AM
  5. Replies: 1
    Last Post: 10-20-2008, 07:35 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •