Jump to content


Output When Running File


  • Please log in to reply
18 replies to this topic

#1 Lofland_00

Lofland_00

    Member

  • Members
  • PipPip
  • 10 posts

Posted 08 February 2011 - 09:39 PM

I am new to JCreator and taking a class. When I Build the program, I get Process completed.  I then run and I do not get the actual results.  All I see is process completed on the general output tab.  Do I have something configured wrong?

/**
* @(#)Calculate.java
*
*
* @author
* @version 1.00 2011/2/8
*/

public class Calculate {

    public static void main(String args[]) {

    int number1;
    int number2;

    System.out.print( "Enter first integer:");
    number1=input.nextInt();

    System.out.print("Enter second integer:");
    number2=input.nextInt();

    //display results
    System.out.printf( "\nSum is %d\n", ( number1+number2));
    System.out.printf("Product is %d\n", (number 1*number2));
    System.out.printf("Difference is %d\n", (number1-number2));
    }//end main

}//end class Calculate

#2 Lofland_00

Lofland_00

    Member

  • Members
  • PipPip
  • 10 posts

Posted 11 February 2011 - 06:18 PM

Please help! I do not get an output on any of the files I build.  It has to be in the setup of the program. I have installed JCreator on 3 different laptops.

//Fig. 2.1: Welcome1.java
//Text-printing program.

public class Welcome1
{
  // main method begins execution of Java application
  public static void main( String[] args )
  {
   System.out.println( "Welcome to Java Programming!" );
  } // end method main
} //end class Welcome 1

#3 FireFox54

FireFox54

    Member

  • Members
  • PipPip
  • 21 posts
  • Gender:Male
  • Location:USA

Posted 13 February 2011 - 09:32 PM

Try running it in the command prompt.  If it runs and works in the command window then there is something wrong the the way JCreator is setup.  

If it is a problem with JCreator then I would first look and see if your the path to your JDK is configured correctly.  On the menu, go to Configure -> Options -> JDK Profiles.  Click new and find the directory of the Java JDK.  

If it is not a problem with compiling the program but running it, I am not sure how to configure the path of the JRE.  I might try installing the JRE then re-installing JCreator.

#4 Lofland_00

Lofland_00

    Member

  • Members
  • PipPip
  • 10 posts

Posted 16 February 2011 - 12:05 AM

I uninstalled all JAVA out of add/remove programs, deleted all folders, installed JDK6011 and installed JCreater 5. I still have the same results. The file builds fine and when you run it, it says process completed but no results. JCreator tech supports says they can not help because I didn't purchase pro.

View PostFireFox54, on 13 February 2011 - 09:32 PM, said:

Try running it in the command prompt.  If it runs and works in the command window then there is something wrong the the way JCreator is setup.  

If it is a problem with JCreator then I would first look and see if your the path to your JDK is configured correctly.  On the menu, go to Configure -> Options -> JDK Profiles.  Click new and find the directory of the Java JDK.  

If it is not a problem with compiling the program but running it, I am not sure how to configure the path of the JRE.  I might try installing the JRE then re-installing JCreator.


#5 FireFox54

FireFox54

    Member

  • Members
  • PipPip
  • 21 posts
  • Gender:Male
  • Location:USA

Posted 16 February 2011 - 01:01 AM

Did you try running it in the command window? What happens when you run the program in the command window?  Is there a difference between the output of the command window and JCerator?

#6 Lofland_00

Lofland_00

    Member

  • Members
  • PipPip
  • 10 posts

Posted 16 February 2011 - 01:46 AM

yes if I did it right here is what I get:

C:\Program Files\Java\jdk1.6.0_11\bin>javac.exe c:\welcome1.java

C:\Program Files\Java\jdk1.6.0_11\bin>


View PostLofland_00, on 16 February 2011 - 12:05 AM, said:

I uninstalled all JAVA out of add/remove programs, deleted all folders, installed JDK6011 and installed JCreater 5. I still have the same results. The file builds fine and when you run it, it says process completed but no results. JCreator tech supports says they can not help because I didn't purchase pro.


#7 FireFox54

FireFox54

    Member

  • Members
  • PipPip
  • 21 posts
  • Gender:Male
  • Location:USA

Posted 16 February 2011 - 02:52 AM

You are running the program javac.exe This is the compiler.  You want to use the compiler to compile the source code then use the java.exe program to run the code produced by the compiler.  
If you don't understand this tell me what you understand the JDK, the compiler, the JRE, and the interpreter is and I will the try to explain it to you.  

View PostLofland_00, on 16 February 2011 - 01:46 AM, said:

yes if I did it right here is what I get:

C:\Program Files\Java\jdk1.6.0_11\bin>javac.exe c:\welcome1.java

C:\Program Files\Java\jdk1.6.0_11\bin>





#8 Lofland_00

Lofland_00

    Member

  • Members
  • PipPip
  • 10 posts

Posted 16 February 2011 - 03:12 AM

C:\Program Files\Java\jre6\bin>java.exe c:\welcome1.class
Exception in thread "main" java.lang.NoClassDefFoundError: c:\welcome1/class
Caused by: java.lang.ClassNotFoundException: c:\welcome1.class
        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)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: c:\welcome1.class.  Program will exit.


View PostFireFox54, on 16 February 2011 - 02:52 AM, said:

You are running the program javac.exe This is the compiler.  You want to use the compiler to compile the source code then use the java.exe program to run the code produced by the compiler.  
If you don't understand this tell me what you understand the JDK, the compiler, the JRE, and the interpreter is and I will the try to explain it to you.


#9 FireFox54

FireFox54

    Member

  • Members
  • PipPip
  • 21 posts
  • Gender:Male
  • Location:USA

Posted 16 February 2011 - 03:29 AM

I see two errors.  
1.  In your program Welcome1 had a uppercase 'w' .  In the command window, you put a lowercase w.  Java is case sensitive.  
2.  When you use the interpreter, you shouldn't put the filename extension.  The interpreter will automatically knows that the file extension will be either .jar or .class .

Try running with the command -> java Welcome1

View PostLofland_00, on 16 February 2011 - 03:12 AM, said:

C:\Program Files\Java\jre6\bin>java.exe c:\welcome1.class
Exception in thread "main" java.lang.NoClassDefFoundError: c:\welcome1/class
Caused by: java.lang.ClassNotFoundException: c:\welcome1.class
        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)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: c:\welcome1.class.  Program will exit.





#10 Lofland_00

Lofland_00

    Member

  • Members
  • PipPip
  • 10 posts

Posted 16 February 2011 - 02:21 PM

C:\Program Files\Java\jre6\bin>java Welcome1
Exception in thread "main" java.lang.NoClassDefFoundError: Welcome1
Caused by: java.lang.ClassNotFoundException: Welcome1
        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)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: Welcome1.  Program will exit.

View PostFireFox54, on 16 February 2011 - 03:29 AM, said:

I see two errors.  
1.  In your program Welcome1 had a uppercase 'w' .  In the command window, you put a lowercase w.  Java is case sensitive.  
2.  When you use the interpreter, you shouldn't put the filename extension.  The interpreter will automatically knows that the file extension will be either .jar or .class .

Try running with the command -> java Welcome1


#11 FireFox54

FireFox54

    Member

  • Members
  • PipPip
  • 21 posts
  • Gender:Male
  • Location:USA

Posted 16 February 2011 - 05:59 PM

Sorry for the confusion I caused you.  Go to the directory of the class / program.  Then use the command java Welcome1.  

View PostLofland_00, on 16 February 2011 - 02:21 PM, said:

C:\Program Files\Java\jre6\bin>java Welcome1
Exception in thread "main" java.lang.NoClassDefFoundError: Welcome1
Caused by: java.lang.ClassNotFoundException: Welcome1
        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)
        at java.lang.ClassLoader.loadClassInternal(Unknown Source)
Could not find the main class: Welcome1.  Program will exit.




#12 Lofland_00

Lofland_00

    Member

  • Members
  • PipPip
  • 10 posts

Posted 17 February 2011 - 02:00 PM

I'm sorry..I am not a programmer.  I am a technology specialist by day...but do not do programming. :)

That worked.

C:\>java Welcome1
Welcome to Java Programming!

That Worked....so now the question is what am I doing wrong in JCreator?  If all else fails..I can build in JCreator and then run in Cmd prompt to test right?

View PostFireFox54, on 16 February 2011 - 05:59 PM, said:

Sorry for the confusion I caused you.  Go to the directory of the class / program.  Then use the command java Welcome1.


#13 FireFox54

FireFox54

    Member

  • Members
  • PipPip
  • 21 posts
  • Gender:Male
  • Location:USA

Posted 17 February 2011 - 05:11 PM

If all else fails cmd prompt usually works, but there is an easier way.

You can test / run in JCreator.  To do this, make sure the file you are working on is contained in the active project.  

Right click on the project that the file is in and click "Set as Active Project"

Click F7 to build / compile the file
Click F5 to test / run the file with the main method in the active project

If you want to build or run an individual file go to the build / run menu and click build file / run file.

(btw if you tell JCreator to run the file it will automatically compile it before running.)

View PostLofland_00, on 17 February 2011 - 02:00 PM, said:

I'm sorry..I am not a programmer.  I am a technology specialist by day...but do not do programming. :)

That worked.

C:\>java Welcome1
Welcome to Java Programming!

That Worked....so now the question is what am I doing wrong in JCreator?  If all else fails..I can build in JCreator and then run in Cmd prompt to test right?




#14 Lofland_00

Lofland_00

    Member

  • Members
  • PipPip
  • 10 posts

Posted 15 March 2011 - 08:25 PM

geez...I had no idea this class was going to be so difficult.  Can you see what I am doing wrong in this one?  I am typed it in exactly as it is in my next book:

/**
* @(#)GradeBook.java
*
* GradeBook application
*
* @author
* @version 1.00 2011/3/14
*/

class GradeBook
{
    // display a welcome message to the GradeBook User
    public void displayMessage ( String courseName )
     {
     System.out.println( "Welcome to the Grade Book for\n%!\n!", courseName );
    }//end method displayMessage
}//end class GradeBook
import java.util.Scanner; //program uses Scanner

public class GradeBookTest
{
    //main method begins program execution
    public static void main(String args[] )
     {

     //create Scanner to obtain input from command window
     Scanner input = new Scanner( System.in);

     // create a GradeBook object and asisgn it to myGradeBook
     GradeBook myGradeBook = new GradeBook();

     //prompt for and input course name
     System.out.println( "Please enter the course name:" );
     String nameOfCourse = input.nextLine(); //read a line of text
     System.out.println(); //outputs a blank line

     //call myGradeBook's displayMessage method
     myGradebook.displayMessage ( nameOfCourse );
    }//end main
}//end class GradeBookTest


then I get this error when trying to run?

/**
* @(#)GradeBook.java
*
* GradeBook application
*
* @author
* @version 1.00 2011/3/14
*/

class GradeBook
{
    // display a welcome message to the GradeBook User
    public void displayMessage ( String courseName )
     {
     System.out.println( "Welcome to the Grade Book for\n%!\n!", courseName );
    }//end method displayMessage
}//end class GradeBook
import java.util.Scanner; //program uses Scanner

public class GradeBookTest
{
    //main method begins program execution
    public static void main(String args[] )
     {

     //create Scanner to obtain input from command window
     Scanner input = new Scanner( System.in);

     // create a GradeBook object and asisgn it to myGradeBook
     GradeBook myGradeBook = new GradeBook();

     //prompt for and input course name
     System.out.println( "Please enter the course name:" );
     String nameOfCourse = input.nextLine(); //read a line of text
     System.out.println(); //outputs a blank line

     //call myGradeBook's displayMessage method
     myGradebook.displayMessage ( nameOfCourse );
    }//end main
}//end class GradeBookTest


Then I get this error when trying to run in command prompt:
C:\Users\kathy.kimbrough\Documents\World College\Java\Assignments\Gradebook>java
GradeBook
Exception in thread "main" java.lang.NoClassDefFoundError: GradeBook
Caused by: java.lang.ClassNotFoundException: GradeBook
        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: GradeBook.  Program will exit.



View PostFireFox54, on 17 February 2011 - 05:11 PM, said:

If all else fails cmd prompt usually works, but there is an easier way.

You can test / run in JCreator.  To do this, make sure the file you are working on is contained in the active project.  

Right click on the project that the file is in and click "Set as Active Project"

Click F7 to build / compile the file
Click F5 to test / run the file with the main method in the active project

If you want to build or run an individual file go to the build / run menu and click build file / run file.

(btw if you tell JCreator to run the file it will automatically compile it before running.)


#15 FireFox54

FireFox54

    Member

  • Members
  • PipPip
  • 21 posts
  • Gender:Male
  • Location:USA

Posted 16 March 2011 - 01:08 AM

Based on the error, did you compile before trying to run the file?

Btw, unlike JCreator, the command prompt will not automatically compile when you tell it to run a project.

#16 Lofland_00

Lofland_00

    Member

  • Members
  • PipPip
  • 10 posts

Posted 16 March 2011 - 02:21 PM

Yes, I am running build in JCreator but I'm not sure it is running correctly.  It never creates the .class file. Does there look to be an error in the code? I'm guessing there must be since it will not run.

#17 FireFox54

FireFox54

    Member

  • Members
  • PipPip
  • 21 posts
  • Gender:Male
  • Location:USA

Posted 16 March 2011 - 05:35 PM

JCreator does not put the .class file in the same directory as the .java files by default.  Are you looking in the same directory for the .class file.  JCreator usually makes a folder for the src files and a folder for the class files.  Look up one level from the src folder and see if there is folder named classes.  

If there is not a folder named "classes" check to see if JCreator or the cmd prompt gives you any errors when you try to compile.  If JCreator, doesn't give you any errors, it is probably creating the .class file

View PostLofland_00, on 16 March 2011 - 02:21 PM, said:

Yes, I am running build in JCreator but I'm not sure it is running correctly.  It never creates the .class file. Does there look to be an error in the code? I'm guessing there must be since it will not run.


#18 Lofland_00

Lofland_00

    Member

  • Members
  • PipPip
  • 10 posts

Posted 16 March 2011 - 06:09 PM

C:\Users\kathy.kimbrough\Documents\World College\Java\Assignments\Gradebook>java
c GradeBook.java
GradeBook.java:19: class, interface, or enum expected
import java.util.Scanner; //program uses Scanner
^
1 error

#19 FireFox54

FireFox54

    Member

  • Members
  • PipPip
  • 21 posts
  • Gender:Male
  • Location:USA

Posted 17 March 2011 - 05:28 PM

Usually i put all my imports right after the the introductory comments.  I also usually make the public class the first one in the file.  Putting the import at the beginning of the file should import it for all the classes in that file.  That is the only thing I notice.  

View PostLofland_00, on 16 March 2011 - 06:09 PM, said:

C:\Users\kathy.kimbrough\Documents\World College\Java\Assignments\Gradebook>java
c GradeBook.java
GradeBook.java:19: class, interface, or enum expected
import java.util.Scanner; //program uses Scanner
^
1 error