Results 1 to 5 of 5
  1. #1
    JonWayn is offline Member
    Join Date
    Mar 2017
    Posts
    5
    Rep Power
    0

    Default Error returning Path and FileStore objects

    I am following code from a java book I am reading. I think I have the code entered exactly but for whatever reason the system cannot find Path returned from the Paths object, and FileStore.
    I am using netbeans. There is a red squiggley under Path and FileStore and the error tooltip says for each Cannot find symbol. What am I missing? Thanks.

    Code below (see lines 27 and 28)


    package com.java24hours;

    import java.io.IOException;
    import java.nio.file.AccessDeniedException.*;
    import java.nio.file.Files;
    import java.nio.file.Paths;
    import javax.swing.*;

    public class FreeSpacePanel extends JPanel {
    JLabel lblSpace = new JLabel("Disk Space: ");
    JLabel space = new JLabel();

    public FreeSpacePanel() {
    super();
    add(lblSpace);
    add(space);

    try {
    setValue();
    } catch(IOException ioe) {
    space.setText("Error");
    System.out.println(ioe.toString());
    }
    }

    private final void setValue() throws IOException {
    Path current = Paths.get(""); //27
    FileStore store = Files.getFileStore(current); //28
    long totalSpace = store.getTotalSpace();
    long freeSpace = store.getUsableSpace();
    double percent = (double)totalSpace / 100 * (double)freeSpace;
    percent = (int)(percent * 100) / (double)100;
    space.setText(freeSpace + " free out of " + totalSpace + "(" + percent + "%)");

    }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default Re: Error returning Path and FileStore objects

    When posting code please wrap it in code tags, that way it keeps its formatting and we get line numbers.

    Anyway, in this case I would guess it is because you haven't imported either Path or FileStore.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,989
    Rep Power
    8

    Default Re: Error returning Path and FileStore objects

    Next time try to hit alt-enter on one of those errors. Netbeans will probably suggest to fix it for you.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  4. #4
    JonWayn is offline Member
    Join Date
    Mar 2017
    Posts
    5
    Rep Power
    0

    Default Re: Error returning Path and FileStore objects

    I did include the import statements

    import java.nio.file.AccessDeniedException.*;
    import java.nio.file.Files;
    import java.nio.file.Paths;

    In fact, I just entered import java.nio.* and the ide took care of making it into 3 separate statements

  5. #5
    JonWayn is offline Member
    Join Date
    Mar 2017
    Posts
    5
    Rep Power
    0

    Default Re: Error returning Path and FileStore objects

    Bingo, that did it and really nice feature of netbeans

    Thank you

Similar Threads

  1. Returning String from objects
    By will71110 in forum New To Java
    Replies: 6
    Last Post: 10-11-2013, 03:52 PM
  2. returning objects explanation please
    By raffs03 in forum New To Java
    Replies: 2
    Last Post: 06-25-2013, 09:30 PM
  3. Returning local objects
    By Lowest0ne in forum New To Java
    Replies: 1
    Last Post: 12-11-2012, 01:14 AM
  4. Function call returning array of objects
    By ShitalJain in forum New To Java
    Replies: 4
    Last Post: 06-25-2011, 09:39 AM
  5. Polygons... returning and passing objects?
    By asherwolf in forum New To Java
    Replies: 3
    Last Post: 07-09-2010, 04:41 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
  •