salvin francis wrote:I see that MainProgram lies under a package called "flashcards"
Which package does class Flashcard lie under ?
Ansamana Sankarray wrote:Class MainProgram and Flashcard are not in the same package and you're creating an instance of Flashcard without importing, plus class Flashcard is on the default package and you can't import from the default package.
Naziru Gelajo wrote:I haven't read through your entire source code but I did notice one odd thing in your main program. It is under the For loop that creates a new object called FC and then adds the same object over and over again in the For loop.
I do not believe that your intention is to create FC over and over again, but a different object each time is that correct? If that is the case, I advise that you revisit and revise that portion of your code.
Ben Hutchenson wrote:
Ansamana Sankarray wrote:Class MainProgram and Flashcard are not in the same package and you're creating an instance of Flashcard without importing, plus class Flashcard is on the default package and you can't import from the default package.
I updated the three files so the package name matches - two had a lower case F. Just to be clear, now that they're all under the same package there will be no importing of anything required, right?
Ben Hutchenson wrote:For my particular project I don't believe it's important to actually label each object in the ArrayList is there? When I say label, I mean declare each one with a variable name that uniquely identifies it (because I can just call deckEntire.get(int) right?
Ben Hutchenson wrote:I had thought that I needed to create objects with a unique name for every iteration (eg. FC0, FC1, FC2, etc) but I saw a post mentioning that the FC object is destroyed after each iteration...
Paul Clapham wrote:
Ben Hutchenson wrote:I had thought that I needed to create objects with a unique name for every iteration (eg. FC0, FC1, FC2, etc) but I saw a post mentioning that the FC object is destroyed after each iteration...
Actually, FC is not an object in that loop. It's a variable name. The variable FC can contain a reference to an object of type Flashcard, but it is not an object itself. It's important to pay attention to the distinction because it's the idea of an object reference which gives Java a lot of its power.
So after each iteration, it isn't true that "the FC object is destroyed". What IS true is that the FC variable goes out of scope -- that means it can't be used outside of the loop.
I updated the three files so the package name matches - two had a lower case F. Just to be clear, now that they're all under the same package there will be no importing of anything required, right?
Paul Clapham wrote:You need to look at the beginning of your code where you (hopefully) have a list of "import" statements. One of them needs to import Flashcard from the package which it's in.
But wait... earlier you said
I updated the three files so the package name matches - two had a lower case F. Just to be clear, now that they're all under the same package there will be no importing of anything required, right?
Since the three classes are in a package, their source code should be in a directory whose name is the name of their package. And they should have been compiled so that their compiled versions are in that same directory (or at least a directory of the same name).
Campbell Ritchie wrote:Welcome to the Ranch
![]()
Have you got it working yet?
It's good to be able to use someting, it's better to understand how it works.
www.goanation.net
Dave Tolls wrote:Can you post the exact javac command you are using to compile this?
Include what directory you are executing it from.
Also, can you check whether you have declared a CLASSPATH in your environment variables...if you have hten that is probably the root cause of your issue.
Ron McLeod wrote:I think there are two issues:
1. The package name and the associated directory/folder are named differently: Flashcards vs. flashcards
2. You should be compiling from one level up, not inside the package directory.
Either rename the Flashcards directory to flashcards and compile from the Desktop directory:
C:\Users\Don Verga Jr\Desktop>javac flashcards\MainProgram.java
or create a directory named flashcards (the package name) under Flashcards (the project name), and compile from the Flashcards directory:
C:\Users\Don Verga Jr\Desktop\Flashcards>javac flashcards\MainProgram.java
Ben Hutchenson wrote:There, I broke it all down to a more simplistic form
Liutauras Vilda wrote:
Ben Hutchenson wrote:There, I broke it all down to a more simplistic form
Have a cow for doing so. That was an excelent idea of yours. And engineering is really about that - about simplifying problems, wheher it is functionality, design or debugging problem.
Ben, you are close, I think you just got typo. When executing class after its compilation, you don’t need to add .java, just simply write: java ClassName (and path to it if you aren’t in that directory already).
So in your case that would be: java Test\Main
Ben Hutchenson wrote:Consistent naming convention: lowercase filename matches lowercase class's name
Ron McLeod wrote:
Ben Hutchenson wrote:Consistent naming convention: lowercase filename matches lowercase class's name
Class names (and associated file names) should use CamelCase and start with a capital letter ... Main.java rather than main.java.
There isn't a reommended way to set the CLASSPATH. You shouldn't set it at all. We asked to see your CLASSPATH last week; please show us what you have.Ben Hutchenson wrote:. . . . I'm certain that I set the classpath in the recommended way. . . . ...
Campbell Ritchie wrote:
There isn't a reommended way to set the CLASSPATH. You shouldn't set it at all. We asked to see your CLASSPATH last week; please show us what you have.Ben Hutchenson wrote:. . . . I'm certain that I set the classpath in the recommended way. . . . ...
It's good to be able to use someting, it's better to understand how it works.
www.goanation.net
Did you use pwd anywhere? As far as I can remember, cd works the same way on Windows® and Unix‑like terminals. Except for root folders; Windows® doesn't support a single root folder like / so you have to write something like d: without cd to move to the root of the d partition. Not certain about the last part.Junilu Lacar wrote:. . . you should be able to do the same thing on Windows, except use "dir" instead of "ls" and "cd" instead of "pwd".