Cannot import custom made java class
Hello
I wrote a java class say (Money.java) which compiled fine. When I was importing it to another class (Account.java), the folowing error message appears:
Account.java.1:'.' expected
import Money;(an errow pointing to ";")
I dont think the code is wrong, because when I cut and attach the Money class code to the front of the Account class it compiled successfully.... I am confused! I wrote the import command according to the text book as follows:
import Money;
public class Account
{............}
By the way, both the Money and Account classes are saved in the save folder... How come it wont let me import...
Looking forward for an early reply.
Thanks
> I wrote the import command according to the text book as follows:
> import Money;
According to which textbook? If it suggests that, it's wrong.
If you don't use packages, you don't need to import your classes.
If you use packages, you need to always use packages throughout your program.
You can't mix.
In older versions of Java, it was possible to import classes from the default package using a statement like:
import Money;
This feature has been removed from Java as of version 1.5. You cannot import classes from the default package.
Note that if your other code (Account.java) is also in the default package, you do not need to import the class Money. Just remove the import statement.
If class Account is in a different package and you want to use class Money, then the only option you have is to put class Money in another package than the default (unnamed) package.