Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

java package problem

Options
  • 03-04-2002 12:06am
    #1
    Registered Users Posts: 6,660 ✭✭✭


    Lately I've been noticing that nothing works like it says on the tin. I paste code directly from tutorials/books and it never bloody works.



    I think my problem might be I'm thinking in terms of C++ classes instead of Java classes. Here's the class definition :
    <<wingaway.java>>
    package wingaway;


    public class wingaway
    {
    String local[][];
    int number;
    public void wingaway()
    {
    number = 0;
    local = new String[20][2];
    }
    ....................


    and the declaration :
    <<shortlist.java>>
    import wingaway.*;

    wingaway mywingaway = new wingaway():

    which gives the error :
    error: File .\wingaway.class does not contain type wingaway as expected, but type wingaway.wingaway. Please remove the file, or make sure it appears in the correct subdirectory of the class path.

    shortlist.java:22: Class wingaway not found.
    wingaway sessionVals = new wingaway();
    ^
    shortlist.java:22: Class wingaway not found.
    wingaway sessionVals = new wingaway();
    ^
    3 errors


Comments

  • Registered Users Posts: 1,994 ✭✭✭lynchie


    Is shortlist.java in a different directory from wingaway.java?? If so, are you adding the directory of your package to the classpath??


  • Closed Accounts Posts: 1,322 ✭✭✭phobos


    Ok if I'm ever importing 3rd party code (meaning anything other than Sun APIs), I copy the java source files to my current project working directory. I then remove any package information from the source file

    // ie.
    package mypackage;

    // the rest of your code goes here

    that way all the classes can reference eachother without you having to worry about physical class locations, dictated by packaging.

    On the otherhand if there is a **** load of classes, I would just reference the root directory of the package in my classpath. ;)

    ;-phobos-)


  • Registered Users Posts: 6,660 ✭✭✭Blitzkrieger


    That seems to be working now - Thanks Phobos & thanks for the advice lynchie.

    I'll probably be buggered by this again in the future tho :) - and now my Cookie statements (also copied directly from Sun tutorials) are wonky. :)


Advertisement