Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Java Java Basics Perfecting the Prototype Reviewing Our Feedback

Itsik Dangoor
seal-mask
.a{fill-rule:evenodd;}techdegree
Itsik Dangoor
Front End Web Development Techdegree Student 5,330 Points

**[solved]** Works good in Eclipse, and treehouse workspace but in Win7 cmd doesn't, WHY?‎

hi,‎ I change the code to work at Eclipse program and run it successfully there. but I went to ‎the command line in Win7 and tried to run it there and it did not work. ‎javac command run good but executing the program with java command gave me ‎error message:‎

my adjusted code for Eclipse that work fine:‎

package n2.usingYourNewTool;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class CodingThePrototype3 {

    public static void main(String[] args) {
          /*  Some terms"
              noun = Person, place or thing
              verb = An action
              adjective = A description used to modified or describe a noun
              Enter your amazing code
          */
        //__Name__ is a __djective__  __noun__. They are always __adverb__  __verb__.

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        String firstName = null;
        String adjective = null;
        String noun = null;
        String adverb = null;
        String verb = null;

        try {
            System.out.println("What is your first name?  ");
            firstName = reader.readLine();

            System.out.println("Enter an adjective:  ");
            adjective = reader.readLine();

            System.out.println("Enter a noun:  ");
            noun = reader.readLine();

            System.out.println("Enter an adverb:  ");
            adverb = reader.readLine();

            System.out.println("Enter a verb ending with -ing:  ");
            verb = reader.readLine();
        } 
        catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        System.out.print("Your Tree Story:\n--------------\n");
        System.out.format("%s is a very %s %s.  ", firstName, adjective, noun);
        System.out.printf("They are always %s %s.\n", adverb, verb);
    }
}

Thank you

6 Answers

Craig Dennis
STAFF
Craig Dennis
Treehouse Teacher

Try running from:

cd "C:\Java Workspaces\TreeHouse - Learn Java\Java Basics\src\"
javac n2\usingYourNewTool\CodingThePrototype3.java
java n2.usingYourNewTool.CodingThePrototype3

The classpath will most likely look in the current directory.

Itsik Dangoor
seal-mask
.a{fill-rule:evenodd;}techdegree
Itsik Dangoor
Front End Web Development Techdegree Student 5,330 Points

yes, I am at the right directory. here is the error message. [alt text](C:/Users/ItsikDangoor/Desktop/forum/1.jpg "error message")

C:\Java Workspaces\TreeHouse - Learn Java\Java Basics\src\n2\usingYourNewTool>javac CodingThePrototype3.java

C:\Java Workspaces\TreeHouse - Learn Java\Java Basics\src\n2\usingYourNewTool>java CodingThePrototype3
Exception in thread "main" java.lang.NoClassDefFoundError: CodingThePrototype3 (wrong name: n2/usingYourNewTool/CodingThePrototype3)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(Unknown Source)
        at java.lang.ClassLoader.defineClass(Unknown Source)
        at java.security.SecureClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.defineClass(Unknown Source)
        at java.net.URLClassLoader.access$000(Unknown Source)
        at java.net.URLClassLoader$1.run(Unknown Source)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: CodingThePrototype3.  Program will exit.
Itsik Dangoor
seal-mask
.a{fill-rule:evenodd;}techdegree
Itsik Dangoor
Front End Web Development Techdegree Student 5,330 Points

tried still the same error: sorry but the site is not uploading the picture of the error message, but this is the same error again: [alt text](C:/Users/ItsikDangoor/Desktop/Tree House/forum/2.jpg "error message")

C:\Java Workspaces\TreeHouse - Learn Java\Java Basics\src>javac CodingThePrototype3.java javac: file not found: CodingThePrototype3.java Usage: javac <options> <source files> use -help for a list of possible options

C:\Java Workspaces\TreeHouse - Learn Java\Java Basics\src>java CodingThePrototype3 Exception in thread "main" java.lang.NoClassDefFoundError: CodingThePrototype3 Caused by: java.lang.ClassNotFoundException: CodingThePrototype3 at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) Could not find the main class: CodingThePrototype3. Program will exit.

Craig Dennis
Craig Dennis
Treehouse Teacher

Sorry I updated it...try again

Itsik Dangoor
seal-mask
.a{fill-rule:evenodd;}techdegree
Itsik Dangoor
Front End Web Development Techdegree Student 5,330 Points

it's working, thanks.

but the interesting 2 things:

  1. why I should go outside the file code folder to src folder and run the two commands.
  2. why I have to run the command java class path with period instead of backslash while javac not? (that's also in java language the path is written!)

thank you Craig

Craig Dennis
Craig Dennis
Treehouse Teacher

You used a package, so it will look in your classpath for n2.usingYourNewTool. Your classpath by default contains the current directory where you are executing your java executable. Because in your original attempt you were outside of the src directory, it couldn't find what you were talking about through normal class loading ways. It will search for those using a directory structure (or JARs, don't worry about this yet).

It's kind of confusing, and we never called java with a dotted name, but that is how you execute a class in a package that has a main method. This is why you don't need to add the .class extension when running the java command, you are really passing it a class name, not a file.

Sorry it's a little confusing, I'm working on a course on running things locally, so I hope to get this clear for everyone here very shortly.

Itsik Dangoor
seal-mask
.a{fill-rule:evenodd;}techdegree
Itsik Dangoor
Front End Web Development Techdegree Student 5,330 Points

yea it's a bit confusing. it's more technical thing to know how to control , not proper programming. But still it is important to know in order not to get stuck or learn how to manage in general in other systems.

I will look forward for your course in those subjects.

thank you