I am working on a project for college and it has me creating an array of ten objects and giving nine of those objects references to one of two different classes in my program, and the last one is just a dud value. The classes that are referenced through the array (Fiction, NonFiction, and Book are all in a sub-directory) and the class does have the import and package statements to match. The compiler was giving me some pretty strange errors that I'm not quite sure about every element of the array. Please help!
Originally posted by Zak Wachtendonk: ... The compiler was giving me some pretty strange errors...
Unfamiliar perhaps, but not strange. In fact, these messages should be very helpful. Look at the first error...
"java182.Project5.Books.NonFiction is not public in java182..."
This is telling you exactly what the problem is. NonFiction is a class in the package java182.Project.5.Books, right? You've imported that package, but if a class in that package does not have public access, then is it accessible from outside of the package?
The next error is basically telling you the same thing, but here the compiler is focusing on NonFiction's constructor, "NonFiction(java.lang.String)." Note the italics I've added...
"NonFiction(java.lang.String) in java182.Project5.Books.NonFiction is not defined in a public class or interface; cannot be accessed from outside package..."
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
Joined: Apr 28, 2005
NonFiction is a class in the package java182.Project.5.Books, right?
Right. The way the directory structure is laid out is somewhat complex unfortunately... /java182 ../Project5 --> This is where BookArray.java is (my code example) ../../Books --> This is where the Fiction and NonFiction classes are
Originally posted by Zak Wachtendonk: ... The way the directory structure is laid out is somewhat complex unfortunately...
Yes, I gathered that from the code and the error messages. I'm guessing this is a requirement of the assignment intended get you thinking about visibility and accessibility with respect to packages. So have you resolved the problem? Do you see why non-public classes in the Books package cannot be accessed by BookArray?
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com