package furniture;

import java.util.*;

public class Program3 {

    public static void main(String[] args) {
        //array of 10 Furniture object references 
        String[] furniture = new String[10];

        String filename = "furnitureData.txt";
        Scanner input = null;

            input = new Scanner(new File(filename));
        }//end try
        catch(FileNotFoundException e){
        }//end catch

    }//end main


with this i can not figure out why it is throwing an error that says " furnitureData.txt (The system cannot find the file specified)
Java Result: 1
BUILD SUCCESSFUL (total time: 3 seconds)"
I get it is saying it can't find the file and the name is spelt the exact same way. I pasted this file in like 5 different places, why is it still doing this? I am not asking for direct answers or gimmies, just guidance!

Below I cannot seem to figure out why my toString method return is not working. Im supposed to read a text file and store it into an array and then output it to how the toString method is. Again no gimmies, just guidance please!

package furniture;

import java.util.*;

public class Furniture extends Program3{
     private double price;
    private double length;
    private double width;

    public Furniture(){
        this.price = 0.0;
        this.length = 0.0;
        this.width = 0.0;

    }//end Furniture

    public double getLength() {
        return length;
    }//end getLength

    public void setLength(double length) {
        this.length = length;
    }//end setLength

    public double getPrice() {
        return price;
    }//end getPrice

    public void setPrice(double price) {
        this.price = price;
    }//end setPrice

    public double getWidth() {
        return width;
    }//end getWidth

    public void setWidth(double width) {
        this.width = width;
    }//end setWidth

    public String toString(){
        return "Furniture{price=" + getPrice() + ", length=" + getLength() ", width=" + getWidth() + "}";
    }//end toString

    public void display(PrintStream output){

    }//end display

    public void readStreamData(String[] furniture){
        Scanner input = new Scanner("furnitureData.txt");
        int count = 0;
          furniture[count] = input.nextLine();
        }//end while loop
    }//end readStreamData


this class is the same for the other two classes i have with the same toString method problem on the return, which only difference is the names changing which the other two are called Desk and Table.

Thank you for your help, guidance, and assistance!

Recommended Answers

All 13 Replies

why it is throwing an error that says " furnitureData.txt

To see where the program is looking for the file, create a File class object with the filename and print out the absolute path for that File object.

why my toString method return is not working

Please explain what it is doing. Post the program's out put or error messages that show the problem.

the actual return line error message says " ';' expected not a statement"
and the line above says "missing return statement"

so honestly I'm not quite too sure.

Please post the full text of the error messages.

that is what it doesn't show up in the output box of netbeans it's underlined in red the only thing that it did say that i didn't type was press alt-enter for hints which wasn't not help at all. sorry

Sorry, I can't see the red lines from here. The compiler should give you some error messasges that look like this: cannot find symbol
symbol  : variable var
location: class TestSorts
         var = 2;

The ^ points to where the problem is.

nope. I have never seen netbeans point to the problem ever. just the error messages when you click on the red circle with the "!" in it on the side of the line. and i just gave what the little pop up said to you. sorry

I don't use your IDE and can't help you use it. I use the javac command to compile java programs and it gives error messages like the one I posted. You need to find out how to use your IDE to have it tell you where the problem is.
The javac command puts a ^ below the place the error is.

That's it for tonight. Back tomorrow.

+ getLength() ", width=" +

It's missing a +

Why doesnt' the IDE tell the OP that? Will the OP have to ask someone to find every syntax error?

I think this is one of those cases where there's an error but the compiler fails to see what the real error was and issues a misleading message. A bit like an extra } is rarely diagnosed as such but instead generates a "class or interface expected".
Hopefull the OP will spot most of these himself; this one wasn't a "jumps out at you" mistake - I too have often spent time staring hopelessly at a long println that had missing or extra delimiters, or had a " in the wrong place...

My compiler puts the ^ underneath where there was a missing + ';' expected
        return "Furniture{price=" + getPrice() + ", length=" + getLength() ", width=" + getWidth() + "}";
                                                                          ^ not a statement
        return "Furniture{price=" + getPrice() + ", length=" + getLength() ", width=" + getWidth() + "}";

Yes. Eclipse puts a red line under the first token after the missing + and explains it as "syntax error on token ,,, etc". I don't use netBeans, so I can't speak to that.

Netbeans unfortuantely underlines the entire line making it hard to see where the error is! And as James said sometimes the IDE generated syntax error messages make things more confusing

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.