*
The moose likes Beginning Java and the fly likes Code not compiling. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Code not compiling." Watch "Code not compiling." New topic
Author

Code not compiling.

Saavan Hirani
Greenhorn

Joined: Nov 15, 2009
Posts: 5
Hi, I seem to be hacing a problem with this basic line of coding, I have checked my curly brackets and all seem to match up, but the <identifier> expected error is still appearing, help would be appreciated.



Firstly what I did was not have the 'class.' statement on the code however when compilin bluej asked me to use it, now this identifier error comes up. It is a simple accessor method and in the same program i have used 2 more with no problems.

Here is the full program code:





Thanks for all the help, very much appreciated from a newbie!
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18760
    
  40

Saavan Hirani wrote:
Firstly what I did was not have the 'class.' statement on the code however when compilin bluej asked me to use it, now this identifier error comes up.


As you already guessed, it is the "class." that is causing the problem. Please remove it -- and then tell us what bluej complained about, that caused you to add it.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 417
You can't use the dot to name anything in Java.
http://java.sun.com/docs/books/tutorial/java/nutsandbolts/variables.html
Vijitha Kumara
Bartender

Joined: Mar 24, 2008
Posts: 3826

Hi Saavan, Welcome to JavaRanch
Few things are incorrect in your code. First you can't use dot(.) in method names. And your "pages" instance variable is declared as String but you are expecting an int in the "getPages()" method.


SCJP 5 | SCWCD 5
[How to ask questions] [Twitter]
Saavan Hirani
Greenhorn

Joined: Nov 15, 2009
Posts: 5
Right, now it has been removed the compiler asks me to add '.class' again however to the line below that, the body of the accessor method in question.
Leandro Coutinho
Ranch Hand

Joined: Mar 04, 2009
Posts: 417
I just note your code. pages is a String. Your get method returns an int.
You need to change the type of the variable pages to int.
You create a variable in the constructor that is never used.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38483
    
  23
And I don't think

return int pages;

will compile.

return pages;

might compile, if pages is the correct type for that method to return. Leandro has already told you, change the type of "pages" to int.
Saavan Hirani
Greenhorn

Joined: Nov 15, 2009
Posts: 5
Ahh appologies, rookie mistake, I have now changed my field pages from String to an int however bluej would still like me to add the '.class'.

EDIT: Right, upon changing the field and removing the int type from the body of the accessor method the code compiled.

Thanks very much for the help, very much appreciated.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38483
    
  23
Oh, you're on BlueJ? Not a program I like at all, I am afraid. I can't see why it wants you to add .class. Please post whatever code you have at present.
Saavan Hirani
Greenhorn

Joined: Nov 15, 2009
Posts: 5
Right seeing that the problem is solved im relieved however im still not aware or what this '.class' is and its true function. Could someone enlighten me please?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38483
    
  23
If I remember correctly (and I probably don't) you put .class after the name of the class and it obtains the Class object for that class.

It doesn't load it; that Class object is already in memory. It simply finds a reference to it.

You will have to check however. It is an advanced feature, which there is a little bit about in the Class class documentation. Also something about it here, but not a lot.

That's the Class class documentation, not the class Class. I should go to the bottom of the class for saying that
Saavan Hirani
Greenhorn

Joined: Nov 15, 2009
Posts: 5
Right, nice one Campbell, thanks for all your help, much appreciated!! Will definatley return if I have anymore problems, which I most likely will.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38483
    
  23
You're welcome And you are bound to have more problems if I help you
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Code not compiling.