Jump to content

int cannot be dereferenced?

- - - - -

  • Please log in to reply
2 replies to this topic

#1
nain33

nain33

    Newbie

  • Members
  • Pip
  • 4 posts
Hey,

I have a problem with my code. We're reading from a file and printing out lines from it depending on what the user enters. When I try to compile it highlights "UI.println(course + room + fName + lName);" and gives the error: int cannot be dereferenced. Anybody know what I'm doing wrong?


    public void printSession(){

        try{

            File exams = new File("examdata.txt");

            Scanner scan = new Scanner(exams);

            int mainDate = UI.askInt("Which day of the month would you like to view?");

            while(scan.hasNext()){

                String course = scan.next();

                String room = scan.next();

                int date = scan.nextInt();

                int students = scan.nextInt();

                String fName = scan.next();

                String lName = scan.next();

                if(date.equalsIgnoreCase(mainDate)){

                    UI.println(course + room + fName + lName);

                }

            }

            UI.println("Done");

        }catch(IOException e){

            UI.printf("File Failure: %s\n", e);

        }

    }



#2
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
If you don't mind my asking, what is the UI object? This may be very pertinent to the error.
Wow I changed my sig!

#3
nain33

nain33

    Newbie

  • Members
  • Pip
  • 4 posts

ZekeDragon said:

If you don't mind my asking, what is the UI object? This may be very pertinent to the error.

UI is an object we get provided with to do all our assignments and it just lets us print, ask etc. I don't know much of how it works.

I got the problem fixed anyway, I used .equalsIgnoreCase when it should have been == because integers dont have 'cases'. It seems real simple now but it was annoying me lol :mad:

Thanks anyway :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users