Jay Gehlot

+ Follow
since Feb 05, 2011
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jay Gehlot

So Ralph, I think I understand what you are saying. Invoice is the class and I am incorrectly trying to import the class, which is obviously not permitted.

I have two class files within the folder C:\Documents and Settings\JGehlot\Desktop\Java Videos\Java Files\Inner_Classes

The first class is Invoice and the second class (which holds main, and call Invoice) is UseInvoice.

Would you suggest to have write the following in the UseInvoice class:

import Inner_Classes.Invoice;
import "Documents and Settings\JGehlot\Desktop\Java Videos\Java Files\Inner_Classes";

I haven't yet gone through the chapter on packages, so I am still trying to find my way here.


13 years ago
Thankyou Tom for your reply to my first post on this site.

Apologies for not using CodeTags, you are right, it would have made the code a lot easier to read and digest.

I've changed the code as you have suggested, in order to instantiate an object for the inner class and this works fine!

Actually the reason I initially did this is because I have been watching CBTNugget videos for the SCJP exam. The videos are actually quite old (created in 2004) for Java 1.4. The videos actually show this (import Invoice.*; code) and the code compiling, which was why I was a little confused as to why this wasn't working on my machine, using Java 1.6.

Maybe this was possible in Java 1.4??

Anyhow thankyou Tom and also thankyou Campbell.
13 years ago

I am learning about Inner Classes and have encountered a compilation error that I am having trouble figuring out.

I have created a class called Invoice (which is the outer, enclosing class) and within this, I have added an inner class called InvoiceItem:

I have created another class called UseInvoice, which creates two objects. One object is an instance of the Invoice class and the other is an instance of the InvoiceItem class.

The Invoice class compiles without any problem, however when trying to compile the UseInvoice class, I get the following error:

C:\Documents and Settings\JGehlot\Desktop\Java Videos\Java Files\Inner_Classes>javac UseInvoice.java
UseInvoice.java:3: package Invoice does not exist
import Invoice.*;
UseInvoice.java:16: cannot find symbol
symbol : class InvoiceItem
location: class UseInvoice
InvoiceItem myInvItem = myInvoice.new InvoiceItem(1,345, "Toy Train", 2) ;
2 errors

C:\Documents and Settings\JGehlot\Desktop\Java Videos\Java Files\Inner_Classes>

Note: UseInvoice.class and Invoice.class and Invoice$InvoiceItem.class are in the same folder (C:\Documents and Settings\JGehlot\Desktop\Java Videos\Java Files\Inner_Classes).

Could someone tell me what I am doing wrong? I think its something to do with the use of the import Invoice.*; statement at the top of the UseInvoice file.


13 years ago