need help with class info and cannot find symbol error.
I having problems with a cannot find symbol error. I cant seem to figure it out.
I have about 12 of them in a program I am trying to do. I was wondering if anyone could help me out?
Here is some code I am working on:
// This will test the invoice class application.
// This program involves a hardware store's invoice.
//import java.util.*;
public class InvoiceTest
{
public static void main( String args[] )
{
Invoice invoice1 = new Invoice( "1234", "Hammer", 2, 14.95 );
// display invoice1
System.out.println("Original invoice information" );
System.out.println("Part number: ", invoice1.getPartNumber() );
System.out.println("Description: ", invoice1.getPartDescription() );
System.out.println("Quantity: ", invoice1.getQuantity() );
System.out.println("Price: ", invoice1.getPricePerItem() );
System.out.println("Invoice amount: ", invoice1.getInvoiceAmount() );
// change invoice1's data
invoice1.setPartNumber( "001234" );
invoice1.setPartDescription( "Yellow Hammer" );
invoice1.setQuantity( 3 );
invoice1.setPricePerItem( 19.49 );
// display invoice1 with new data
System.out.println("Updated invoice information" );
System.out.println("Part number: ", invoice1.getPartNumber() );
System.out.println("Description: ", invoice1.getPartDescription() );
System.out.println("Quantity: ", invoice1.getQuantity() );
System.out.println("Price: ", invoice1.getPricePerItem() );
System.out.println("Invoice amount: ", invoice1.getInvoiceAmount() );
}
}
and that uses this class file:
public class Invoice
{
private String partNumber;
private String partDescription;
private intquantityPurchased;
private double pricePerItem;
public Invoice( String ID, String desc, int purchased, double price )
{
partNumber = ID;
partDescription = desc;
if ( purchased >= 0 )
quantityPurchased = purchased;
if ( price > 0 )
pricePerItem = price;
}
public double getInvoiceAmount()
{
return quantityPurchased * pricePerItem;
}
public void setPartNumber( String newNumber )
{
partNumber = newNumber;
System.out.println(partDescription+" has changed to part "+newNumber);
}
public String getPartNumber()
{
return partNumber;
}
public void setDescription( String newDescription )
{
System.out.printf("%s now refers to %s, not %s.\n",
partNumber, newDescription, partDescription);
partDescription = newDescription;
}
public String getDescription()
{
return partDescription;
}
public void setPricePerItem( double newPrice )
{
if ( newPrice > 0 )
pricePerItem = newPrice;
}
public double getPricePerItem()
{
return pricePerItem;
}
}
Any tips for helping me out?
Hello, and welcome to the forum.
A couple of tips:
- when posting code, use code tags, it makes it easier to read your code. See http://forum.java.sun.com/help.jspa?sec=formatting;
- when receiving compiler or runtime errors, copy-n-paste them exactly as you see them on your screen.
> - when receiving compiler or runtime errors,> copy-n-paste them exactly as you see them on your> screen.And make it clear which line they're occurring on. The error message includes the line number, but we're not going to count your lines.
However "cannot find symbol" means you're trying to use a method, variable, class, or constructor that doesn't exist. Maybe you misspelled something, or messed up the upper/lower case, or maybe the thing is out of scope, or maybe just not defined, or maybe the method parameters you're passing don't match the signature. The error message will tell you exactly which method, etc. you're trying to use that doesn't exist.
oh sorry about that, here are some errors that it is giving me for example:
InvoiceTest.java:16: cannot find symbol
symbol : method println(java.lang.String,java.lang.String)
location : class Invoice
System.out.println("Part number: ", invoice1.getPartNumber() );
The . after system.out is what it is pointing to.
And I'm compiling from the command prompt and I cant seem to be able to copy those errors on the screen for you.
> oh sorry about that, here are some errors that it is
> giving me for example:
>
> InvoiceTest.java:16: cannot find symbol
> symbol : method
> println(java.lang.String,java.lang.String)
> location : class Invoice
> System.out.println("Part number: ",
> invoice1.getPartNumber() );
>
> The . after system.out is what it is pointing to.
The compiler is telling you there is no method println(...) which takes 2 Strings. You can only put 1 String in it. Try this:// See how code tags make code reading easier?
System.out.println("Part number: "+invoice1.getPartNumber());
The + sign will concatenate invoice1.getPartNumber() after "Part number: " forming only one String.
> And I'm compiling from the command prompt and I cant
> seem to be able to copy those errors on the screen
> for you.
Assuming this is a cmd prompt in Windows, either
Right click in the main part of the window, select Mark from the menu that pops up, highlight what you want, hit the Enter key to copy it.
OR
Right click in the title bar, select Properties, click the Options tab, check QuickEdit mode, hit OK. After doing this, you can just drag to select and then hit enter to copy--no need for "Mark." If you want it to always be this way, select "For all windows with this name" or whatever from the dialog that comes up when you're OKing the property change.
> System.out.println("Part number:
> "+invoice1.getPartNumber;
> The + sign will concatenate invoice1.getPartNumber()
> after "Part number: " forming only one String.
I added the plus sign and it gives me more errors:
C:\>javac InvoiceTest.java
InvoiceTest.java:16: operator + cannot be applied to java.lang.String
System.out.println("Part number: ",+ invoice1.getPartNumber() );
^
InvoiceTest.java:17: cannot find symbol
symbol : method getPartDescription()
location: class Invoice
System.out.println("Description: ", + invoice1.getPartDescription() );
^
InvoiceTest.java:17: cannot find symbol
symbol : method println(java.lang.String,int)
location: class java.io.PrintStream
System.out.println("Description: ", + invoice1.getPartDescription() );
^
InvoiceTest.java:18: cannot find symbol
symbol : method getQuantity()
location: class Invoice
System.out.println("Quantity: ", + invoice1.getQuantity() );
^
InvoiceTest.java:18: cannot find symbol
symbol : method println(java.lang.String,int)
location: class java.io.PrintStream
System.out.println("Quantity: ", + invoice1.getQuantity() );
^
InvoiceTest.java:19: cannot find symbol
symbol : method println(java.lang.String,double)
location: class java.io.PrintStream
System.out.println("Price: ", + invoice1.getPricePerItem() );
^
InvoiceTest.java:20: cannot find symbol
symbol : method println(java.lang.String,double)
location: class java.io.PrintStream
System.out.println("Invoice amount: ", + invoice1.getInvoiceAmount() );
^
InvoiceTest.java:24: cannot find symbol
symbol : method setPartDescription(java.lang.String)
location: class Invoice
invoice1.setPartDescription( "Yellow Hammer" );
^
InvoiceTest.java:25: cannot find symbol
symbol : method setQuantity(int)
location: class Invoice
invoice1.setQuantity( 3 );
^
InvoiceTest.java:30: operator + cannot be applied to java.lang.String
System.out.println("Part number: ", + invoice1.getPartNumber() );
^
InvoiceTest.java:31: cannot find symbol
symbol : method getPartDescription()
location: class Invoice
System.out.println("Description: ", + invoice1.getPartDescription() );
^
InvoiceTest.java:31: cannot find symbol
symbol : method println(java.lang.String,int)
location: class java.io.PrintStream
System.out.println("Description: ", + invoice1.getPartDescription() );
^
InvoiceTest.java:32: cannot find symbol
symbol : method getQuantity()
location: class Invoice
System.out.println("Quantity: ", + invoice1.getQuantity() );
^
InvoiceTest.java:32: cannot find symbol
symbol : method println(java.lang.String,int)
location: class java.io.PrintStream
System.out.println("Quantity: ", + invoice1.getQuantity() );
^
InvoiceTest.java:33: cannot find symbol
symbol : method println(java.lang.String,double)
location: class java.io.PrintStream
System.out.println("Price: ", + invoice1.getPricePerItem() );
^
InvoiceTest.java:34: cannot find symbol
symbol : method println(java.lang.String,double)
location: class java.io.PrintStream
System.out.println("Invoice amount: ", + invoice1.getInvoiceAmount() );
^
16 errors
> I added the plus sign and it gives me more errors:See a difference in these two lines?System.out.println("Part number: " + invoice1.getPartNumber());System.out.println("Part number: ", + invoice1.getPartNumber());
Oh I didn't see the comma, I removed it and it gives me only six errors now. Something about my get and set parameters. I will continue to look at it.
Here is some more stuff it is giving me:
C:\>javac InvoiceTest.java
InvoiceTest.java:17: cannot find symbol
symbol : method getPartDescription()
location: class Invoice
System.out.println("Description: " + invoice1.getPartDescription() );
^
InvoiceTest.java:18: cannot find symbol
symbol : method getQuantity()
location: class Invoice
System.out.println("Quantity: " + invoice1.getQuantity() );
^
InvoiceTest.java:24: cannot find symbol
symbol : method setPartDescription(java.lang.String)
location: class Invoice
invoice1.setPartDescription( "Yellow Hammer" );
^
InvoiceTest.java:25: cannot find symbol
symbol : method setQuantity(int)
location: class Invoice
invoice1.setQuantity( 3 );
^
InvoiceTest.java:31: cannot find symbol
symbol : method getPartDescription()
location: class Invoice
System.out.println("Description: " + invoice1.getPartDescription() );
^
InvoiceTest.java:32: cannot find symbol
symbol : method getQuantity()
location: class Invoice
System.out.println("Quantity: " + invoice1.getQuantity() );
^
6 errors
C:\>
> Oh I didn't see the comma, I removed it and it gives
> me only six errors now.
The number of errors doesn't say much. When you resolve one of the errors, they all can disappear or even can cause more errors to appear.
It's always a good idea to write a bit of code, compile it and run it to see if it works. After you're sure that specific part works properly, write some more code. Don't write everything at once.
> Something about my get and
> set parameters. I will continue to look at it.
>
> Here is some more stuff it is giving me:
>
> C:\>javac InvoiceTest.java
> InvoiceTest.java:17: cannot find symbol
> symbol : method getPartDescription()
> location: class Invoice
> System.out.println("Description: " +
> invoice1.getPartDescription() );
The compiler is telling you that there is no method called getPartDescription in your Invoice class.
> The compiler is telling you that there is no method> called getPartDescription in your Invoice class.Or at least none that takes no arguments. :-)
> >
>
> Or at least none that takes no arguments. :-)
Yes, you're right <mumble>you old nitpicker</mumble>...
Before posting my answer to the OP, I made sure there was no method (regardless of the parameters) with that name in his code just to keep things simple.
; )
I got it to work! Now I just need to doctor up the output.Thanks so much for your help everyone. I appreciate it very much.
> I got it to work! Now I just need to doctor up the> output.> > Thanks so much for your help everyone. I appreciate> it very much.Good to hear that John.; )Good luck.