File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes help with Progamme Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "help with Progamme" Watch "help with Progamme" New topic
Author

help with Progamme

Wolfgang Obi
Ranch Hand

Joined: Dec 05, 2005
Posts: 134
hi this is a class with methods i wrote....
it's upposed to give out the number of days from 001 AD till the entered date.
it just isnt compiling...what exactly am i doing wrong here?


PS: days is declared as :
private int days;
in "class1"

[ June 05, 2006: Message edited by: Wolfgang Obi ]
[ June 05, 2006: Message edited by: Wolfgang Obi ]
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 10911
    
  12

can you post the EXACT error message you are getting? the error message gives you a BIG hint on what's wrong. I can't try and compile this, since i don't have class1.


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Wolfgang Obi
Ranch Hand

Joined: Dec 05, 2005
Posts: 134
okay, here's Class1,....
i think it wou bring more if i post Class1...

i actually posted this programme in some other thread sometime last week or so, but here it is again......


[ June 05, 2006: Message edited by: Wolfgang Obi ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36478
    
  16
Several minor syntactical errors:
  • print statements started and not finished.
  • IM not available, but you have already told us you keep that elsewhere.
  • class1 instead of Class1. BTW Class1 is a dreadful name for a class.
  • the variable "marker" doesn't seem to have been declared anywhere.
  • and several others

  • You might find checking the spelling of class1 and Class1 throughout will sort out several errors.

    Now go back to every error message you get, and read the code where it says to read, and the two lines before, and remember what the error messages mean.
    fred rosenberger
    lowercase baba
    Bartender

    Joined: Oct 02, 2003
    Posts: 10911
        
      12

    If you can't understand the error messages, please post them here, EXACTLY as they appear. they usually tell you exactly what's wrong, once you learn how to read them.
    Wolfgang Obi
    Ranch Hand

    Joined: Dec 05, 2005
    Posts: 134
    Originally posted by fred rosenberger:
    If you can't understand the error messages, please post them here, EXACTLY as they appear. they usually tell you exactly what's wrong, once you learn how to read them.


    @Campbell Ritchie
    the formatting/naming is not the problem, i probably made mistakes while copying and pasting into the forum....the print /printf commands compile perfectly....

    okay i have about 11 in all,... here they are in a nutshell (didnt copy everything....this is whats really relevant):

    1. .....\Kalender6_2.java:40: days has private access in Class1
    if(days == 29){ // comes up everytime "days" is used

    2. .....Kalender6_2.java:44: cannot find symbol
    variable marker
    location: class Kalender6_2
    return marker;

    3. .....\Kalender6_2.java:81: cannot find symbol
    symbol : variable dayGroup
    location: class Kalender6_2
    (365 - daysSoFar) - (dayGroup[month] - day);

    4. ......\Kalender6_2.java:111: cannot find symbol
    symbol : variable year
    //same goes for month, as well as day -> one error message each.

    location: class Kalender6_2

    5. ........\Kalender6_2.java:113: cannot find symbol
    symbol : variable totalDays
    location: class Kalender6_2
    kalender.absoluteDay(totalDays,daysTillEndOfYear);

    //above also goes for "daysTillEndOfYear"....

    6. ......\Kalender6_2.java:116: cannot find symbol
    symbol : variable numOfDays
    location: class Kalender6_2
    ("The total number of days since 001 aD is: "+numOfDays);
    kalender.daysInYear(year);

    [ June 05, 2006: Message edited by: Wolfgang Obi ]
    fred rosenberger
    lowercase baba
    Bartender

    Joined: Oct 02, 2003
    Posts: 10911
        
      12

    1) like the message says, days is private in Class1. therefore, you can't access it in Kalender6_2. try making it protected.

    2) you declare marker inside your if and else condition:

    }

    i don't know if you know about scope rules, but basically a variable disappears once it goes out of scope. basically, it's at the closing curly brace for whatever opening curly brace immediatly precedes the delcaration. in other words, whichever branch you go through, as soon as you leave this if/else block, marker goes out of scope. so on the next line, marker doesn't exist. you can try doing this:



    try fixing those, recompile, and see what's left.
    Wolfgang Obi
    Ranch Hand

    Joined: Dec 05, 2005
    Posts: 134
    try fixing those, recompile, and see what's left.


    well, i fixed those errors...now the first two of the six i listed have been fixed , thanx

    but errors 3 - 6 still persist....
    what d'you suggest there ?
    [ June 05, 2006: Message edited by: Wolfgang Obi ]
    Joanne Neal
    Rancher

    Joined: Aug 05, 2005
    Posts: 3168
        
      10
    The errors say that certain symbols cannot be found.
    So first check that you have declared those symbols somewhere.
    If you have declared them then check that they are in scope at the line given in the error message.
    If the variable is declared and in scope, then check for differences in spelling and case between the declaration and the use of the variable.
    [ June 05, 2006: Message edited by: Joanne Neal ]

    Joanne
    fred rosenberger
    lowercase baba
    Bartender

    Joined: Oct 02, 2003
    Posts: 10911
        
      12

    Do you understand scoping rules? and the difference between a member variable and a method variable?

    look at where you declare dayGroup. according to scope rules, where does this go out of scope? and then, where are you trying to use it?
    Wolfgang Obi
    Ranch Hand

    Joined: Dec 05, 2005
    Posts: 134
    Do you understand scoping rules? and the difference between a member variable and a method variable?


    well i must confess my understanding of the rules are not very founded,...



    look at where you declare dayGroup. according to scope rules, where does this go out of scope? and then, where are you trying to use it?


    okay, starting with daygroup:
    daygroup is defined in "daysInMonth" (a public method) in "Class1"... therefore it should be accessible if "Kalender6_2" extends "Class1" shouldnt it?
    [ June 05, 2006: Message edited by: Wolfgang Obi ]
    fred rosenberger
    lowercase baba
    Bartender

    Joined: Oct 02, 2003
    Posts: 10911
        
      12

    a variable defined in a method is only available in that method. once that method exits, that variable is lost forever.

    if you want a variable to be available, you should define it as a class level variable.

    look at this:


    any beginning java book should talk about scoping rules. i know Bruce Eckel has a free one online you should be able to get, or the Sun tutorials would have it. i'd suggest you read up on it a little.

    also, this code was written off the top of my head, so it may not be perfect...
    [ June 05, 2006: Message edited by: fred rosenberger ]
    Wolfgang Obi
    Ranch Hand

    Joined: Dec 05, 2005
    Posts: 134
    okay, so according to ur example (and to my prior understanding):

    fredsName and fredsAge are available in "mySubclass" because it extends "myClass".

    then why arent the method "daysInMonth" and the object "daygroup" available to me in "Kalender6_2" after extending "Class1" by this class (Kalender6_2) ??....
    this is what has been confusing me most about the error message output.

    @Joanne Neal
    to the best of my knowledge and understanding so far (and yes i have looked in some beginners books on java) all the variables bing asked for seem to be in scope....im not getting any further....

    maybe someone can just look through the code again and let me know where im using variables out of scope,....or where im not defining/initialising them properly?

    i'd really appreciate it ...thank you.
    [ June 05, 2006: Message edited by: Wolfgang Obi ]
    fred rosenberger
    lowercase baba
    Bartender

    Joined: Oct 02, 2003
    Posts: 10911
        
      12

    the METHODS are available in the subclass. you can call the method "daysInMonth" in your subclass. but the variable dayGroup ONLY exists inside that method. if you are not in that method, that variable doesn't exist.

    so when the compiler says

    3. .....\Kalender6_2.java:81: cannot find symbol
    symbol : variable dayGroup
    location: class Kalender6_2
    (365 - daysSoFar) - (dayGroup[month] - day);


    look at line 81 of Kalender6_2.java. you are not inside that method, so you don't have that variable. if you need dayGroup to be visible outside of the method daysInMonth, then move it up where you have

    private int days


    although, again, if you want other classes to be able to see it, don't make it private.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: help with Progamme
     
    Similar Threads
    Date accessor method error
    how to test the setter methods
    Custom Date class and Appointment class
    BigDecimal to Date Conversion
    cannot find symbol inside String?