Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: ClassNotFoundException (bit weird)

  1. #1
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default ClassNotFoundException (bit weird)

     
    package ConsoleApplicationsSamples;
     
    import java.io.InputStreamReader;
    import java.io.IOException;
     
    /**
     * Simple program that accepts a character (letter or number) and
     * display its location in ASCII code using .read() method of
     * InputStreamReader class in java.io package.
     *
     * 
     */
     
    public class ASCIIDisplay {
     
        private static InputStreamReader isr = new InputStreamReader(System.in);
     
        public static void main(String[] args) throws IOException {
     
            int keyIn;
     
            System.out.print("Enter The Character That You Want To Locate In ASCII: ");
            keyIn = isr.read();
     
            System.out.println(keyIn);
        }
    }

    after a month that i saved this file .. i run it a while ago...

    and this is the output

    run:
    java.lang.NoClassDefFoundError: xTestsx/ASCIIDisplay
    Caused by: java.lang.ClassNotFoundException: xTestsx.ASCIIDisplay
            at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
    Could not find the main class: xTestsx.ASCIIDisplay.  Program will exit.
    Exception in thread "main" Java Result: 1
    BUILD SUCCESSFUL (total time: 0 seconds)


    and when i changed the package to where it belongs andi edit the code by typing anything in the environment ("asdjashdkjahdkajsdhkasd") and 'UNDO' it
    it compiled perfectly....

    and i revert it back from the package where it belongs,compiled it,
    there's an error again.... 'ClassNotFoundException' so i type lots of letters again then UNDO it , and it compiled again perfectly .


    whats going on?

    i tried to clean it up... same thing happens.. same solution
    Last edited by chronoz13; October 13th, 2009 at 10:48 AM.


  2. #2
    Junior Member
    Join Date
    Apr 2011
    Location
    Pune, India
    Posts
    11
    My Mood
    Cool
    Thanks
    0
    Thanked 2 Times in 2 Posts

    Default Re: ClassNotFoundException (bit weird)

    Hi Very first thing, once the java code is compilled and run fine... mean it can work any where in word.
    But you have to maintain the package stucture..
    You you are replacing the java file some where else, you need to change the package...

    just change the package name in your java code, save it in the same folder and compile it... it should work fiine..
    Hardik Jadhav

Similar Threads

  1. [SOLVED] ClassNotFoundException - Please Help
    By igniteflow in forum Exceptions
    Replies: 11
    Last Post: October 3rd, 2010, 10:50 PM