.class expected

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • krinz10
    New Member
    • Mar 2009
    • 3

    .class expected

    Hi, I am doing an apartment rentals program but i need to bubble sort the array of a user defined class customerDetails (this entails all the details of the customer) However, when i am calling that there is an error:
    ------------------------------------------------------------------------------------------------------------
    apartmentRental Code.java:476: '.class' expected
    Bubblesort(cust omer[], n );
    ^
    apartmentRental Code.java:476: ')' expected
    Bubblesort(cust omer[], n );
    ^
    2 errors

    ----jGRASP wedge2: exit code for process is 1.
    ----jGRASP: operation complete.
    --------------------------------------------------------------------------------------------------------------
    Here is the code:
    public void sortCustomer()
    {
    customerDetails[] customer = new customerDetails[myCustomerLinke dList.sizeOfCus tomerList() - 1];
    int[] cusIDArray = new int[myCustomerLinke dList.sizeOfCus tomerList()-1];
    int z = 0;
    File fileName = new File("C:\\Users \\Sony\\Desktop \\ComputerScien ceDossier\\Java Code3\\customer InBinary.dat");
    int cusID = 0;
    customerDetails readCustomerRec ord = new customerDetails ();
    char status;
    char[] fName = new char[30];
    char[] lName = new char[30];
    char[] dob = new char[10];
    char[] passportNo = new char[10];
    char[] mobileNo = new char[10];
    char[] email = new char[50];
    int j = 0;

    try {
    RandomAccessFil e raf = new RandomAccessFil e(fileName, "r");
    raf.seek(0);
    try {
    while (true){
    status = raf.readChar();
    readCustomerRec ord.cusID = raf.readInt();

    for(j=0; j<30; j++) {
    fName[j] = raf.readChar();
    }
    readCustomerRec ord.fName = readCustomerRec ord.fName.copyV alueOf(fName);

    for(j=0; j<30; j++) {
    lName[j] = raf.readChar();
    }
    readCustomerRec ord.lName = readCustomerRec ord.lName.copyV alueOf(lName);

    for(j=0; j<10; j++) {
    dob[j] = raf.readChar();
    }
    readCustomerRec ord.dob = readCustomerRec ord.dob.copyVal ueOf(dob);

    for(j=0; j<10; j++) {
    passportNo[j] = raf.readChar();
    }

    readCustomerRec ord.passportNo = readCustomerRec ord.passportNo. copyValueOf(pas sportNo);

    for(j=0; j<10; j++) {
    mobileNo[j] = raf.readChar();
    }

    readCustomerRec ord.mobileNo = readCustomerRec ord.mobileNo.co pyValueOf(mobil eNo);

    for(j=0; j<50; j++) {
    email[j] = raf.readChar();
    }

    readCustomerRec ord.email = readCustomerRec ord.email.copyV alueOf(email);
    cusIDArray[z] = readCustomerRec ord.cusID;
    customer[z] = readCustomerRec ord;
    }


    }
    catch (EOFException eof){
    raf.close();
    }
    catch (IOException E){
    System.out.prin tln( "Problems reading " + fileName );
    raf.close();

    }

    }
    catch (IOException X){

    System.out.prin tln("IO Problems with " + fileName );

    }
    int a = 0;
    int n =myCustomerLink edList.sizeOfCu stomerList()-1;
    System.out.prin tln(n);
    Bubblesort(cust omer[], n );
    for(a = 0; a < n; a++){
    System.out.prin tln(cusIDArray[a]);
    }


    }
    public void Bubblesort (customerDetail s data[],int n) {
    int i,j;
    customerDetails tmp;

    for (i=0; i<n-1; i++) {
    for (j=0; j<n-i-1; j++)
    if (data[j].cusID > data[j+1].cusID) {
    tmp = data[j];
    data[j] = data[j+1];
    data[j+1] = tmp;
    }
    }
    }
    --------------------------------------------------------------------------------------------------------------
    can u please help me figure this out...my brain is dead after hours of fiddling around...
    cheers x
    Last edited by Stewart Ross; Mar 13 '09, 05:15 PM. Reason: Moved from Access forum to Java
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    When you want to pass an array to a method as a parameter you simply mentions its name, i.e. you don't use the square brackets. so:

    Code:
    Bubblesort(customer, n );
    btw, there is also no need to pass the length of the array as well, i.e. the array 'knows' its length.

    kind regards,

    Jos

    Comment

    • krinz10
      New Member
      • Mar 2009
      • 3

      #3
      many thanks :)
      but now i am getting a null pointer exception [line is in italics]
      I know the file is there, i have checked the path as well.
      Q: is it fine to put data[j].cusID when the array has cusID as part of it?
      ------------------------------------------------------------------------------------------------------
      public void Bubblesort (customerDetail s data[],int n) {
      int i,j;
      customerDetails tmp;

      for (i=0; i<n-1; i++) {
      for (j=0; j<n-i-1; j++)
      if (data[j].cusID > data[j+1].cusID) {
      tmp = data[j];
      data[j] = data[j+1];
      data[j+1] = tmp;
      }
      }
      }
      ----------------------------------------------------------------------------------------------------
      I don't know what is null?? - any ideas?

      cheers x

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Every non-primitive (i.e. not int, double etc.) variable actually is just a reference, a pointer to an object. You have to make it point to an object. For member variables, if you don't make it point to an object, it is said to point to nothing which is represented by the value 'null', i.e. such a variable has a value null. Of course you can't dereference ('use the dot notation') on a variable with a null value.

        kind regards,

        Jos

        Comment

        • krinz10
          New Member
          • Mar 2009
          • 3

          #5
          Thanks I will check again.

          cheers x

          Comment

          Working...