Results 1 to 2 of 2
  1. #1
    caps_lock is offline Member
    Join Date
    Jan 2009
    Posts
    12
    Rep Power
    0

    Default Long Cannot Be Dereferenced?

    i am getting the error in the title, how do I solve this please?

    Java Code:
    import java.io.File;
    
    public class TestingClass{
        public static void main( String [] args ) {
            File actual = new File(".");
            
              
            
            for( File f : actual.listFiles())
            for( File e : actual.listFiles()){
                {
    if (f.length().equals(e.length())) {
        System.out.println (e.getName() + f.length());
    }
            }
        }
    }
    
    
    
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    f.length returns a long, a primitive type. You can't call a method such as .equals on this as it is similar to trying to call this:
    Java Code:
    if (3.equals(4)) { //...
    Use == instead here.

    Java Code:
    if (f.length() == e.length()) {
    Last edited by Fubarable; 01-18-2009 at 02:16 AM.

Similar Threads

  1. Replies: 2
    Last Post: 11-30-2008, 03:24 PM
  2. Calculate sum of long integer!
    By Julingo in forum New To Java
    Replies: 2
    Last Post: 09-09-2008, 11:50 PM
  3. It takes very long time.....
    By iresha in forum Advanced Java
    Replies: 6
    Last Post: 05-11-2008, 02:31 AM
  4. Error: convert from String to long
    By bbq in forum New To Java
    Replies: 1
    Last Post: 06-29-2007, 07:23 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •