programming help

import java.io.*;

import java.util.Scanner;

import java.util.ArrayList;

// imports needed files

publicclass FileRead

{

publicstaticvoid main(String[] args)

{

int sum = 0;

int max = 0;

int min = 1000;

int count = 0;

//creates all instance variables and sets them to correct values

try

{

FileReader reader =new FileReader("input.txt");

//creates a new filereader that read in from input.txt

Scanner in =new Scanner(reader);

//creates a new scanner with input of reader

ArrayList<Integer> numbers =new ArrayList<Integer>();

//creates an array list for the numbers

while(in.hasNextInt())

//checks to see if there is more data

{

int x = in.nextInt();

//sets the number equal to x

numbers.add(x);

//adds the number to the array list

sum = sum + x;

//finds the sum of the numbers

if(x > max)

{

max = x;

}

//finds the max if the numbers

if(x < min)

{

min = x;

}

//finds the min of the numbers

count++;

//finds the number oif numbers

}

PrintWriter out =new PrintWriter("output.txt");

//creates a new printwriter that prints the output to a file called output.txt

out.println("The sum is: " + sum);

out.println("The maximum value is: " + max);

out.println("The minimum value is: " + min);

out.println("The number of values is: " + count);

//prints values

out.close();

//closes the output.txt file

}

catch(IOException e)

{

System.out.println("Error processing file: " + e);

}

//catches the IOException if found

}

}

There is my program and my input.txt is just a bunch of numbers. My question is how do you run this program? I go to run java application and it gives me this message. Exception in thread "main" java.lang.NoClassDefFoundError: FileRead. Can anyone help me please?

[3822 byte] By [cs_tarheel34a] at [2007-10-2 15:59:39]
# 1

compile your program like this:

open a command shell, navigate to the directory where FileRead.java lives, and type:

javac *.java

You should see a FileRead.class file in that same directory.

to run your program, type:

java -classpath . FileRead

Note the "dot" after -classpath. It tells the class loader to look in the current directory for FileRead.class.

Go read about how CLASSPATH and the class loader works once you have this running.

%

duffymoa at 2007-7-13 16:26:11 > top of Java-index,Java Essentials,New To Java...
# 2
I have only been programming for about 6 months and dont really know what that means what u just replied with? Can anyone make it easier for me to follow or have another way? Sorry
cs_tarheel34a at 2007-7-13 16:26:11 > top of Java-index,Java Essentials,New To Java...
# 3
MOD gave pretty clear instructions. What exactly don't you understand?
floundera at 2007-7-13 16:26:11 > top of Java-index,Java Essentials,New To Java...
# 4
I use Textpad so do I go under tools and than go into Run? Than wheres the directory?
cs_tarheel34a at 2007-7-13 16:26:11 > top of Java-index,Java Essentials,New To Java...
# 5
I can get into the directory where my file is stored at. But where do I type those things at?
cs_tarheel34a at 2007-7-13 16:26:11 > top of Java-index,Java Essentials,New To Java...
# 6
As MOD said you need the command shell.Click StartClick Run...Type cmdClick OK
floundera at 2007-7-13 16:26:12 > top of Java-index,Java Essentials,New To Java...
# 7
in textpad ckeckout options.. find fields something like classpath then add a dot (.) at end of the textfield provided(note : you wil hav to add ; or : before the dot )
saravanan.chennaia at 2007-7-13 16:26:12 > top of Java-index,Java Essentials,New To Java...
# 8

How about using a basic IDE like say Dr.Java, it's a good tool for beginners learning Core Java .. ?

However, using a textpad will make you more adept at coding in Java since you don't get to see your mistakes till the time you compile on the command line and hence, makes a better impression in your mind regarding the folly.

Jinnovatora at 2007-7-13 16:26:12 > top of Java-index,Java Essentials,New To Java...
# 9
Im really clueless on what everyone is trying to tell me. I have no idea when to type these things or where I'm suppose to type them.
cs_tarheel34a at 2007-7-13 16:26:12 > top of Java-index,Java Essentials,New To Java...
# 10

Do you know how to use the command shell? You really should be using this a lot when you are starting out with Java. flounder's instructions in reply #6 should give you a command shell.

Assuming that you know where your Java source file is (the file that contains your Java code), you should be able to get to the directory of where this file is using the change directory command.

C:>cd C:\path\to\FileRead.java

then type the commands that duffymo gave in reply #1.

Ares-Mana at 2007-7-13 16:26:12 > top of Java-index,Java Essentials,New To Java...
# 11
How much bigger do you need the spoon to be?If you can't follow the instructions already provided then might I suggestyou change courses!
floundera at 2007-7-13 16:26:12 > top of Java-index,Java Essentials,New To Java...
# 12

Have you every heard of DOS, the Command Prompt etc. etc. etc.

These guys told you to go to command prompt.

If you using Windows, Click Start>Run

Type cmd and click OK.

You must see a new window where you can type commands

And then type the following command

1) javac *.java

2) java -classpath . FileRead

these are very basic thing and are taught at a very initial level.

Dheeraj_Gabaa at 2007-7-13 16:26:12 > top of Java-index,Java Essentials,New To Java...
# 13
if you're using textpad as your source code editor. just do ctrl+1 to compile the source code then after compiling do ctrl+2 to run your program. or just go to the tools menu of textpad, select Compile Java then Run Java Application.
raymond_momoa at 2007-7-13 16:26:12 > top of Java-index,Java Essentials,New To Java...
# 14
If someone doesn't know how to use the command prompt, think of all the things he wouldn't be able to do with Java.
Ares-Mana at 2007-7-13 16:26:12 > top of Java-index,Java Essentials,New To Java...
# 15
> If someone doesn't know how to use the command> prompt, think of all the things he wouldn't be> able to do with Java.Be positive, man... he can always wait for someone to create a friendly UI. :)
aniseeda at 2007-7-20 22:46:52 > top of Java-index,Java Essentials,New To Java...