aspose file tools*
The moose likes Cattle Drive and the fly likes Bad Class Error Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "Bad Class Error" Watch "Bad Class Error" New topic
Author

Bad Class Error

Donald R. Cossitt
buckaroo
Ranch Hand

Joined: Jan 31, 2003
Posts: 401
The following is in preparation for the Lookup assignment. I have created the Lookup.java file - it compiles. I have created four support classes - they compile. They are merely the basics to get started filling in with appropriate coding to accomplish the assignment.

The other two support classes are copy / paste duplicates of Video.java just the names changed according to requirements of the assignment. The problem is the Furniture and BookOnTape classes are accepted when instanced in the Lookup.java file but the Video instance gives this error:

All of the support classes are in the same package "rental" with the same format, etc. So what is wrong with this picture?
doco


doco
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9046
    
  10
Do you have a file named "Video.class" in more than one subdirectory? I've had this error when I have (a copy of) the same class in more than one place.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
John Hembree
hired gun
Ranch Hand

Joined: Mar 07, 2003
Posts: 250

eeeewwwww wwwweeeeee!!! Look at all that free code Martha! I have a printout of the requirements for that assignment on my desk as I was about to start working on it myself.
I copied your code and created just the two files in the same directory. I removed the import statement for rental in Lookup and didn't include any package information in Video.java, afterwards I created the abstract class for Thing.java, compiled and ran Lookup and everything worked fine the way you have it, so the error must be related to Marilyn's suggestion or something is messed up with the package statements / file placements.
Don't know that I would of added all that package information to the assignment.
[ April 16, 2003: Message edited by: John Hembree ]
Donald R. Cossitt
buckaroo
Ranch Hand

Joined: Jan 31, 2003
Posts: 401
Other than the package thingy, what was shown was just about verbatum in the assignment. So, I am not sure I let too much of a cat out of the bag.
At any rate, I was merely experimenting with the package thingy and very curious as to why it didn't work.
1. The rental directory is the only place the class files were / are.
2. Everything compiles nicely if I move the class files to the same directory as the Lookup.java file.
3. Classpath variables are sufficient. Or at least enough that the compiler does not complain that "package rental does not exist - import rental.*;"

Now I am left with the same dillema whether or not I use this for the assignment or not. Suggestions? Be gentle John .
Thanks
doco
John Hembree
hired gun
Ranch Hand

Joined: Mar 07, 2003
Posts: 250

I was just teasing, I rarely see any code posted in this forum, besides if the sheriff didn't say anything, why should I. It's not my town, I'm just a citizen here.
  • I went back and added the package information to the files including Thing.java.
  • I moved Video.java and Thing.java into a sub-directory below Lookup.java called "rental".
  • I compiled Lookup, which compiled Thing and Video automatically.
  • I verified that the .class files were where they were suppose to be according to Marilyn's post
  • I ran Lookup and received a different error, something about not being able to access Video.
  • I then added public to the constructor in Video.java and recompiled and everything worked fine


  • I also didn't alter any of my environment variables. Lookup is not part of the rental package but only imports rental per your code.
    So check if you need to add "public" to your video construct.
    jason adam
    Chicken Farmer ()
    Ranch Hand

    Joined: May 08, 2001
    Posts: 1932
    If you don't add public to the constructor, then only classes in the same package, or subclasses of that class, will be able to instantiate an object of that type.
    When you don't supply an access modifier (public, private, protected), then the default is considered "package", which is somewhat misleading since subclasses, even those in different packages, also have access.
    It's pretty much a good practice to label your constructors public unless you have specific reasoning not to. For example, Singletons most often use a private constructor and a static access method. That way, only that class can actually instantiate itself.
    Explains why with John's changes, the errors don't occur. Good catch there
    John Hembree
    hired gun
    Ranch Hand

    Joined: Mar 07, 2003
    Posts: 250

    Am I allowed to re-use the text file feature from SortNames to store my video, audio, furniture object information in text files rather than embedding the info in Lookup.java? No doubt, it's overkill, but I do that a lot.
    Donald R. Cossitt
    buckaroo
    Ranch Hand

    Joined: Jan 31, 2003
    Posts: 401
    Thanks John & Jason.

    John mused:
    ===========
    Am I allowed to re-use the text file feature from SortNames to store my video, audio, furniture object information in text files rather than embedding the info in Lookup.java?

    Yeah, what John said. This actually makes better sense to me than an embedded HashMap - Course there are a lot of things I don't know; really, it's true! :roll:
    doco
    jason adam
    Chicken Farmer ()
    Ranch Hand

    Joined: May 08, 2001
    Posts: 1932
    Well, it gives the nitpicker more to go over, and that is usually frowned upon, but I think I'll defer to Marilyn's opinion on this matter.
    Marilyn de Queiroz
    Sheriff

    Joined: Jul 22, 2000
    Posts: 9046
        
      10
    Seems like the assignment requires a HashMap containing a dozen things to rent.
    Barry Gaunt
    Ranch Hand

    Joined: Aug 03, 2002
    Posts: 7729
    Don't forget the nitpicker only has to say "nope" and that takes 0.2 seconds to type. But for you it could mean an hour's undoing what you thought was cool... (I know, been there, done that... )


    Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
    Getting someone to think and try something out is much more useful than just telling them the answer.
    John Hembree
    hired gun
    Ranch Hand

    Joined: Mar 07, 2003
    Posts: 250

    It's the part in the requirements section that says
    Give each of your classes relevant attributes

    To me that seems relative to an individual's perspective. Of course the instructor's solution is 120 lines so I could calculate it backwards and try to figure out how many attributes could span the three data types and then divide them accordingly. However if this is Say-4b of OOP, then I would hope for a little tolerance in code re-use and implementation of some of the logic learned to date.
    I like Marilyn's answer myself... nice and vague.
    John Hembree
    hired gun
    Ranch Hand

    Joined: Mar 07, 2003
    Posts: 250

    Originally posted by Barry Gaunt:
    Don't forget the nitpicker only has to say "nope" and that takes 0.2 seconds to type. But for you it could mean an hour's undoing what you thought was cool... (I know, been there, done that... )

    It was at least an hour of undoing probably more..
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Bad Class Error