Results 1 to 4 of 4
  1. #1
    justOne is offline Member
    Join Date
    Jul 2011
    Posts
    11
    Rep Power
    0

    Default Running object-oriented in Unix

    I have written 2 classes, one is an object, and the other manipulates the object and has the main method. It runs perfectly in my IDE (Eclipse), but since this will be running on a server, it needs to also compile and run in Unix/Linux.

    Company.java is the object, and Magic.java is the rest.

    My commands are as follows:
    javac Company.java Magic.java
    java Company Magic

    Here is where I get an error.

    Exception in thread "main" java.lang.NoClassDefFoundError: Company (wrong name: Counts/Company)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader. java:631)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :615)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:141)
    at java.net.URLClassLoader.defineClass(URLClassLoader .java:283)
    at java.net.URLClassLoader.access$000(URLClassLoader. java:58)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 197)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 06)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:2 47)

    Can someone tell me what I'm doing wrong? Thanks.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,412
    Rep Power
    25

    Default Re: Running object-oriented in Unix

    NoClassDefFoundError: Company (wrong name: Counts/Company)
    The java command was expecting a class of name: Company but found one named: Counts.Company

    Is there a package statement in the Company.java file? That will change the class name to include the package name meaning that you have to tell the java command the full classname(includes the package and the classpath for the java command must point to the folder that contains the package folder.

    Easiest way to get this to work is remove the package statement.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    justOne is offline Member
    Join Date
    Jul 2011
    Posts
    11
    Rep Power
    0

    Default Re: Running object-oriented in Unix

    Thanks! That fixed my problem.

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,412
    Rep Power
    25

    Default Re: Running object-oriented in Unix

    Later you will need to learn how to use packages and the classpath.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. help for Object Oriented Programming RMI
    By clapton in forum New To Java
    Replies: 0
    Last Post: 03-20-2012, 06:42 PM
  2. New to object-oriented
    By fluteattack in forum New To Java
    Replies: 6
    Last Post: 03-28-2011, 01:43 PM
  3. Help in object oriented programming .
    By renu in forum New To Java
    Replies: 18
    Last Post: 10-26-2010, 07:57 PM
  4. Object Oriented
    By GraemeH in forum New To Java
    Replies: 3
    Last Post: 03-29-2009, 07:50 PM
  5. Object- Oriented guide?
    By sciguy77 in forum New To Java
    Replies: 4
    Last Post: 01-18-2009, 03:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •