Close

Results 1 to 8 of 8
  1. #1
    DF VIP Member OrangeJuicey's Avatar
    Join Date
    Aug 2006
    Location
    London
    Posts
    1,283
    Thanks
    1
    Thanked:        4
    Karma Level
    289

    Help Error Msg's driving me crazy in Java. Code provided.

    Code:
    package AP3.AE3;
    import AP3.AE3.utils.*;
    import java.util.Scanner;
    //import java.io.*;
    
    public class RunVetSystem{
    
        //  VetSystem vs;
        // PetOwner currentOwner=null;
        //  Pet currentPet=null;
        String command1;
    
            public void main(String args[]){
                //    UtilityCode.loadData(vs);
                System.out.print("Vetsystem> "); // prompt the user for input
                //System.out.flush();
    
                    //Read commands from the input
                //  Scanner s = new Scanner(System.in);
                //  s.useDelimiter("cmd:");
                //  command1 = s.next();
                command1 = "locateOwner";
        if (command1== "locateOwner"){
            System.out.println("tester");
        }
        if(command1== "listPets"){
                System.out.println("tester");
                //    if (currentOwner!=null)
                    {
                        //      for(int i=0; i>currentOwner.petcounter; i++){
                        //          System.out.println(currentOwner.ownedPets[i]); }
                    }
        //      else System.out.println("no currentOwner is set yet");
    
    
                if(command1== "selectPet"){
                System.out.println("tester");
                }
                if(command1== "listMedicalHistory"){}
                    //else{
                    //throw new NoCommandException("The command you typed was not recognised.");
                }
        }
            }
    This code should load a VetSystem that i've created but instead the compiler comes up with these errors.

    java RunVetSystem
    Exception in thread "main" java.lang.NoClassDefFoundError: RunVetSystem (wrong name: AP3/AE3/RunVetSystem)
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

    okay thats with most of the code commented out, can anyone see why this would be happening? Is it something to do with the fact that the main isn't static? loadData is a none static method and cannot be used in a static environment. The program compiles fine with no errors.

  2. #2
    DF VIP Member /dev/null's Avatar
    Join Date
    Feb 2004
    Location
    Behind You
    Posts
    2,952
    Thanks
    0
    Thanked:        0
    Karma Level
    451

    Default Re: Error Msg's driving me crazy in Java. Code provided.

    Your main method should be "public static void main(String [] args])"

  3. #3
    DF VIP Member OrangeJuicey's Avatar
    Join Date
    Aug 2006
    Location
    London
    Posts
    1,283
    Thanks
    1
    Thanked:        4
    Karma Level
    289

    Default Re: Error Msg's driving me crazy in Java. Code provided.

    its okay, i fixed that by making my variables static, I still have a problem when i try to load the database. Can someone tell me how do you get strings from System.in with Scanner??

    Scanner s = new Scanner(System.in);
    s.useDelimiter("cmd:");
    String command1 = s.next();

    that doesn't seem to work could someone point in the right direction. Thanks.

  4. #4
    DF VIP Member /dev/null's Avatar
    Join Date
    Feb 2004
    Location
    Behind You
    Posts
    2,952
    Thanks
    0
    Thanked:        0
    Karma Level
    451

    Default Re: Error Msg's driving me crazy in Java. Code provided.

    In your code you have:

    // command1 = s.next();
    command1 = "locateOwner";

    - You put s.next() into command1 then immediately overwrite it with the string "locateOwner"

  5. #5
    DF VIP Member OrangeJuicey's Avatar
    Join Date
    Aug 2006
    Location
    London
    Posts
    1,283
    Thanks
    1
    Thanked:        4
    Karma Level
    289

    Default Re: Error Msg's driving me crazy in Java. Code provided.

    Yep, thats not the problem i just put that there to see if i could just set command1 manually and get it to perform the command. I've got the input working, the fact tht its in the package was stopping it compiling,

    Got a new problem, i can't get those if loops to work. Where it says if(command1=="locateOwner"){....} they just don't work, any ideas?

  6. #6
    DF VIP Member blacksheep's Avatar
    Join Date
    Jun 2006
    Location
    Manchester
    Posts
    3,877
    Thanks
    87
    Thanked:        265
    Karma Level
    546

    Default Re: Error Msg's driving me crazy in Java. Code provided.

    use String.compareTo() rather than ==. Think its compareTo check the API to be sure.

  7. #7
    DF VIP Member /dev/null's Avatar
    Join Date
    Feb 2004
    Location
    Behind You
    Posts
    2,952
    Thanks
    0
    Thanked:        0
    Karma Level
    451

    Default Re: Error Msg's driving me crazy in Java. Code provided.

    Code:
    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html#compareTo(java.lang.String)
    Also, for debugging, check the length of both strings - you may have non-printable characters in there. I cannot remember what the case is in java but I know c adds the "\n" at the end from stdin.

    Also, just a quick thought aside - you are having users enter a full command for what they want to do. Eg: they have to enter "locateOwner" which is tedious and long-winded. Would it not be a better idea having a menu driven option like:

    Code:
    Enter choice: 
    1) locateOwner
    2) listPets
    .
    .
    .
    Then all your user needs to do is enter a number corresponding to their choice. Simple switch statement to process it. Food for thought?
    Last edited by /dev/null; 2nd December 2006 at 04:25 PM.

  8. #8
    DF VIP Member OrangeJuicey's Avatar
    Join Date
    Aug 2006
    Location
    London
    Posts
    1,283
    Thanks
    1
    Thanked:        4
    Karma Level
    289

    Default Re: Error Msg's driving me crazy in Java. Code provided.

    Yes thats much better but i'm working for an assignment, so I didn't decide. Its all down to whats written on a piece of paper in front of me.

Similar Threads

  1. Code for Blaupunkt Car 300 Radio?
    By fais in forum Radio Decoding
    Replies: 8
    Last Post: 30th March 2004, 03:38 PM
  2. Wireless Acking or War Driving
    By unclex in forum System Security
    Replies: 53
    Last Post: 14th June 2003, 04:26 PM
  3. Wireless Acking or War Driving
    By unclex in forum PC Problems
    Replies: 55
    Last Post: 22nd January 2003, 09:44 PM
  4. Eurotunnel cheap fare or discount code - priviledge member?
    By shedsounds in forum Cheapskates Corner
    Replies: 2
    Last Post: 5th September 2002, 10:21 AM

Social Networking Bookmarks

Posting Permissions

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