User Name
Password
AppleNova Forums » Programmer's Nook »

Problems creating a new instance of a Java class


Register Members List Calendar Search FAQ Posting Guidelines
Problems creating a new instance of a Java class
Thread Tools
Ryan
Veteran Member
 
Join Date: May 2004
Location: Promise Land of Trustafarians
 
2007-11-16, 21:53

So, I have an error that doesn't seem to make any sense. I'm simply trying to create a new instance of a class (Payment.java) inside another class (VendingMachine.java).

Code:
from VendingMachine private void pay(double price, boolean gui) { Scanner Sc = new Scanner(in); DecimalFormat ff = new DecimalFormat("0.00"); double paid=0.0; Payment pay = new Payment(price);
Now, the compile error says:

Code:
VendingMachine.java:89: cannot find symbol symbol : constructor Payment(double) location: class VendingMachine.Payment pay = new Payment(price); ^ 1 error
Now, if I remove the "price" argument from the line creating the new instance in VendingMachine, it compiles, but obviously doesn't work, as I never wrote the default constructor. The constructor in Payment is:

Code:
public class Payment extends JFrame { private variables public Payment(double price) { super("Insert Coins");
Obviously, these aren't full excerpts of code. But does anyone have any idea why this doesn't compile?
  quote
Kickaha
Veteran Member
 
Join Date: May 2004
 
2007-11-16, 22:00

You have the proper 'import Payment', right?
  quote
Ryan
Veteran Member
 
Join Date: May 2004
Location: Promise Land of Trustafarians
 
2007-11-16, 22:06

Quote:
Originally Posted by Kickaha View Post
You have the proper 'import Payment', right?
They're in the same folder, so I didn't think it was necessary, but I'll give it a shot.

And... same error.

edit: Okay, I've fixed it. I didn't realize there was already a Payment class in Java, which explains the error, I guess. I changed the name of my class to something else and it works fine now.

Last edited by Ryan : 2007-11-16 at 22:19.
  quote
Posting Rules Navigation
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Post Reply

Forum Jump
Thread Tools
Similar Threads
Thread Thread Starter Forum Replies Last Post
iPhone: Running List of Problems Kraetos Apple Products 206 2007-07-28 13:22
10.4.9 now available in SW Update FFL Apple Products 118 2007-04-28 22:34
please explain 'class' in PHP nassau Programmer's Nook 12 2006-07-13 13:36
Problems creating pdf files from Excel 2004 fwtong Genius Bar 5 2006-06-19 22:35
Very disappointed by my G5 and Java... nicolas_bol Apple Products 69 2006-04-29 18:15


« Previous Thread | Next Thread »

All times are GMT -5. The time now is 03:51.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004 - 2024, AppleNova