Page 1 of 2 12 LastLast
Results 1 to 20 of 28
  1. #1
    thegluups is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default Compiling probem "cannot find symbol"

    Hey, I've just started Java.

    All the three files are in the same folder, and the two last files were given to me in the exercise, so I'm guessing they're probably right.

    I can't figure out why I am getting this error message. I have checked that all the variables are correctly written, and that the file path is right.

    Help would be much appreciated.

    Java Code:
     package media.Hybrid.Documents.Cambridge.ComputerScience.CST1.Java.Tick1; 
    
    public class PackedLong {
     
      public static boolean get(long packed, int position) {
    
        long check = packed>>position & 1 ;
        return (check == 1);
      }
    
      public static long set(long packed, int   position, boolean value) {
        if (value) {
    	packed = packed - (position<<1) ;
      
        }
        else {
    	packed = packed + (position<<1) ;
          
        }
        return packed;
      }
    }
    And the two "test programs given to me "

    Java Code:
    package media.Hybrid.Documents.Cambridge.ComputerScience.CST1.Java.Tick1; 
    
    public class TestBit {
      public static void main(String[] args) throws Exception {
        long currentValue = Long.decode(args[0]);
        int position = Integer.parseInt(args[1]);
        boolean value = PackedLong.get(currentValue, position);
        System.out.println(value);
      }
    }
    Java Code:
    package media.Hybrid.Documents.Cambridge.ComputerScience.CST1.Java.Tick1;  
    
    public class SetBit {
     public static void main(String [] args) throws Exception {
      long currentValue = Long.decode(args[0]);
      int position = Integer.parseInt(args[1]);
      boolean value = Boolean.parseBoolean(args[2]);
      currentValue = PackedLong.set(currentValue,position,value);
      System.out.println(currentValue); } }
    And I get the following error message

    Java Code:
    thegluups@thegluups-laptop:/media/Hybrid/Documents/Cambridge/ComputerScience/CST1/Java$ javac Tick1/TestBit.java
    Tick1/TestBit.java:7: cannot find symbol
    symbol  : variable PackedLong
    location: class media.Hybrid.Documents.Cambridge.ComputerScience.CST1.Java.Tick1.TestBit
        boolean value = PackedLong.get(currentValue, position);
                        ^
    1 error

  2. #2
    Syntax's Avatar
    Syntax is offline Member
    Join Date
    Jan 2010
    Location
    Georgia
    Posts
    20
    Rep Power
    0

    Default

    Hey I'm not familiar with ">>" but you can't just add "& 1" to the end.

    Wrong: if (x>y&<3)

    Right: if(x>y && x<3
    11th Grade | Beginner Programmer | Looking into College

  3. #3
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Quote Originally Posted by Syntax View Post
    Hey I'm not familiar with ">>" but you can't just add "& 1" to the end.

    Wrong: if (x>y&<3)

    Right: if(x>y && x<3
    << Is a bit shift operator. It shifts the value by 1 bit to the left.

    1 << 2 = 4

  4. #4
    Lil_Aziz1's Avatar
    Lil_Aziz1 is offline Senior Member
    Join Date
    Dec 2009
    Location
    United States
    Posts
    343
    Rep Power
    5

    Default

    quad64bit, bit has to do w/ binary numbers right? I'm just curious because I want to learn about bits/binary numbers so I can understand the << and the several other bit operators supported by Java.
    "Experience is what you get when you don't get what you want" (Dan Stanford)
    "Rise and rise again until lambs become lions" (Robin Hood)

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Yeah, remember that everything on a computer is binary at some level. You can perform binary operations on basic number data types (short, int, long, etc..). See this:Java Bitwise Tutorials

  6. #6
    thegluups is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default

    I deleted the & 1, since i've just realised i don't need it, since there's the equality test at the end, but I'm still getting the same error ?

    ... This is so confusing ..:(

  7. #7
    AndreB's Avatar
    AndreB is offline Senior Member
    Join Date
    Dec 2009
    Location
    Stuttgart, Germany
    Posts
    114
    Rep Power
    0

    Default

    you didnt import the PackedLong class.
    (Or am i wrong?)
    "There is no foolproof thing; fools are too smart."
    "Why can't you solve my Problem ?"

  8. #8
    thegluups is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default

    I don't think so ... Didn't know you had to do that,

    I've added this to my code
    Java Code:
    import media.Hybrid.Documents.Cambridge.ComputerScience.CST1.Java.Tick1.*;
    ahead of public class on both setbit and testbit,

    but i now get the following error message
    Java Code:
     thegluups@thegluups-laptop:/media/Hybrid/Documents/Cambridge/ComputerScience/CST1/Java$ javac Tick1/TestBit.java
    Tick1/TestBit.java:9: cannot find symbol
    symbol  : variable PackedLong
    location: class media.Hybrid.Documents.Cambridge.ComputerScience.CST1.Java.Tick1.TestBit
        boolean value = PackedLong.get(currentValue, position);
                        ^
    1 error
    in any case, do i still need to import the package even though on all the programs the package name is the same?

    I'm sorry for being so dumb about it, but I only started java a couple of hours ago :p and am therefore very confused about compiling issues

  9. #9
    AndreB's Avatar
    AndreB is offline Senior Member
    Join Date
    Dec 2009
    Location
    Stuttgart, Germany
    Posts
    114
    Rep Power
    0

    Default

    no, i was wrong, you don't need to import class if they are in the same package.

    well... what compiler do you use? Eclipse dont goive any error and it runs fine
    "There is no foolproof thing; fools are too smart."
    "Why can't you solve my Problem ?"

  10. #10
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,531
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by thegluups View Post
    I deleted the & 1, since i've just realised i don't need it, since there's the equality test at the end, but I'm still getting the same error ?
    Leaving out the '& 1' part of the expression is incorrect, put it back in. b.t.w. there are more errors in the code of that PackedLong utility class. The 'set' method is also not correct.

    kind regards,

    Jos

  11. #11
    thegluups is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default

    AndreB, i use the linux command line javac /java. Does it work fine for you? That's strange, since JosAH said there were more error in the code?

    JosAH, I'm sorry what do you mean when you say that hte "set" method is not correct? are you talking about setbit? Because if that's the case, I'm pretty sure it is, since it was given to me as part of the exercise, and it's been the same for a few years, so they would have noticed by now if they had made a mistake?

    Again... sorry to be such an idiot with regards to java

  12. #12
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,531
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by thegluups View Post
    AndreB, i use the linux command line javac /java. Does it work fine for you? That's strange, since JosAH said there were more error in the code?

    JosAH, I'm sorry what do you mean when you say that hte "set" method is not correct? are you talking about setbit? Because if that's the case, I'm pretty sure it is, since it was given to me as part of the exercise, and it's been the same for a few years, so they would have noticed by now if they had made a mistake?

    Again... sorry to be such an idiot with regards to java
    I was talking about the 'set' method in the first file. Better make that:

    Java Code:
    if (value)
    	packed |= 1L << position;
        else
    	packed &= ~(1L << position);
        return packed;
    kind regards,

    Jos

  13. #13
    adz
    adz is offline Member
    Join Date
    Jul 2009
    Posts
    35
    Rep Power
    0

    Default

    Post what you are using to compile/run it; must have something to do with that since the code looks fine and someone's already said it works in Eclipse. Can't think what else it could possibly be.

  14. #14
    AndreB's Avatar
    AndreB is offline Senior Member
    Join Date
    Dec 2009
    Location
    Stuttgart, Germany
    Posts
    114
    Rep Power
    0

    Default

    Quote Originally Posted by thegluups View Post
    I'm sorry for being so dumb about it, but I only started java a couple of hours ago :p and am therefore very confused about compiling issues
    Quote Originally Posted by thegluups View Post
    Again... sorry to be such an idiot with regards to java
    Please stop saying it. This is annoying. And it does not help to solve your problem either.

    Java Code:
    javac -cp . TestBit.java
    javac -cp . SetBit.java
    works for me. The -cp option includes the classpath and thats where your files are.
    You would be better off with using some IDE.
    "There is no foolproof thing; fools are too smart."
    "Why can't you solve my Problem ?"

  15. #15
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,531
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by thegluups View Post
    Java Code:
    package media.Hybrid.Documents.Cambridge.ComputerScience.CST1.Java.Tick1; 
    
    public class TestBit {
    And I get the following error message

    Java Code:
    thegluups@thegluups-laptop:/media/Hybrid/Documents/Cambridge/ComputerScience/CST1/Java$ javac Tick1/TestBit.java

    I don't think your package structure is right: you can't compile a class media.Hybrid.Documents.Cambridge.ComputerScience.C ST1.Java.Tick1.TestBit as if it were named Tick1.TestBit.

    kind regards,

    Jos

  16. #16
    thegluups is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default

    I've installed NetBeans and the same error ocmes up when I type my program in the IDE

    I get "cannot find symbol" variable Packed Long

    and location media.Hybrid.Documents.Cambridge.ComputerScience.C ST1.Java.Tick1.SetBit;

    the problem is PackedLong is in media.Hybrid.Documents.Cambridge.ComputerScience.C ST1.Java.Tick1.PackedLong right?

    If I don't need to import the package (because all the files are in the same one) then could it be that i've specified the wrong package name?

    This is what my exercice sheet says : The PackedLong class does not contain a special "main" method. Consequently this means that it
    cannot be executed directly using the java command line program. Do not add a main method to this
    class; instead create two extra Java source files inside the same directory structure. Save the following
    program into (your file path)/TestBit.java:

  17. #17
    AndreB's Avatar
    AndreB is offline Senior Member
    Join Date
    Dec 2009
    Location
    Stuttgart, Germany
    Posts
    114
    Rep Power
    0

    Default

    did you put your java file into the directory:

    media/Hybrid/Documents/Cambridge/ComputerScience/CST1/Java/Tick1/ .. ?

    if not, then thats our problem. if you remove the package declaration you can just put your file in your project root folder
    "There is no foolproof thing; fools are too smart."
    "Why can't you solve my Problem ?"

  18. #18
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,531
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by AndreB View Post
    did you put your java file into the directory:

    media/Hybrid/Documents/Cambridge/ComputerScience/CST1/Java/Tick1/ .. ?

    if not, then thats our problem. if you remove the package declaration you can just put your file in your project root folder
    He can't do that if he is not supposed to alter those two 'given' classes: they use the PackedLong class without explicitly importing it so it has to be a class in the same pacakage as those other two classes.

    kind regards,

    Jos

  19. #19
    thegluups is offline Member
    Join Date
    Jan 2010
    Posts
    10
    Rep Power
    0

    Default

    I think so : all my files are in the folder media/Hybrid/Documents/Cambridge/ComputerScience/CST1/Java/Tick1

    In that folder I've got the three java files for packedlong, setbit, testbit, and the class file for packedlong.

    Am I calling packedlong.get / packedlong.set the wrong way? Should I add a pathname to those?

  20. #20
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,531
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by thegluups View Post
    I think so : all my files are in the folder media/Hybrid/Documents/Cambridge/ComputerScience/CST1/Java/Tick1

    In that folder I've got the three java files for packedlong, setbit, testbit, and the class file for packedlong.

    Am I calling packedlong.get / packedlong.set the wrong way? Should I add a pathname to those?
    What happens when you do this:

    Java Code:
    javac -cp . media/Hybrid/Documents/Cambridge/ComputerScience/CST1/Java/Tick1/*.java
    while your current working directory is one level up from the 'media' sub directory?

    kind regards,

    Jos

Page 1 of 2 12 LastLast

Similar Threads

  1. Error "can not find symbol variable"
    By FullMetalHollow in forum New To Java
    Replies: 5
    Last Post: 10-04-2009, 09:51 PM
  2. cannot find symbol for "list.addFirst"
    By alexbryan_08 in forum New To Java
    Replies: 10
    Last Post: 08-26-2009, 08:55 AM
  3. Replies: 1
    Last Post: 06-30-2009, 02:32 PM
  4. Replies: 1
    Last Post: 10-20-2008, 07:35 AM
  5. "Cannont find symbol Constructor" error
    By Welsh in forum New To Java
    Replies: 7
    Last Post: 01-25-2008, 12:12 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
  •