exception error

InTraining
InTraining used Ask the Experts™
on
i'm learning java in school and i wanted to try and do some of my work at home but when ever i try to run a java program i get "Exception in thread "main" java.lang.NoClassDefFoundError: *Program name*"

here is the code i used:

import java.util.Random;

public class matrix
{
    public static void main(String args[])
    {
        int num = 0;
        int count;
        Random generator = new Random();

        for(count=0;count>-1;count++)
        {
            num = generator.nextInt(1);
            System.out.println(num);
        }
    }
}
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
try using this code

import javax.swing.*;
import java.util.Random;

     public class test {
         
          static int num=0;
          static Random generator = new Random();
               
          public static void main (String args[]) {
               for (int i=0; i>-1 && i<10; i++) {
                    num = generator.nextInt(100);
                    System.out.println (""+num);
               }
          }
         
     }

hope this is what u wan

Commented:
You must run the program as:

java matrix
Mick BarryJava Developer
Top Expert 2010

Commented:
And ensure your class can be found in your classpath.
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

Author

Commented:
class path and everything is fine... i'm pretty sure its not with my code... i think i might need somthing because no matter what program i run it doesnt work(sorri i forgot to put that part)

Author

Commented:
i just put the code so you would know that i knew what i was doing and as a simple example
Mick BarryJava Developer
Top Expert 2010

Commented:
can u post the exact error
and how u are running it?

Author

Commented:
exact error is as i posted originaly:

Exception in thread "main" java.lang.NoClassDefFoundError: matrix

thats the message i get when runnign the program above and what do you mean how am i running it? explain please
Hi,

   Check your class path.... or try to run with the command below :

java -classpath {DIR} matrix

- where {DIR} is the directory path that you store the matrix.class

regards,
Kok Choon.

Author

Commented:
the compiler im using is TextPad which has the location of javac.exe and java.exe already *hot-keyed* for lack of better word
Hi,

   you can configure the textpad's java tool by Configure - Preferences - Tools - run java appliaction, set the initial folder to the folder that u store the matrix.class.

hth,
Kok Choon.

Author

Commented:
i did what you said kokchoon78 with no aperant effect it just said the same thing...
Mick BarryJava Developer
Top Expert 2010

Commented:
it is not finding matrix.class so it must not be available in the classpath.
what command are you typing to run it?

Author

Commented:
i did what you said kokchoon78 with no aperant effect it just said the same thing...

Author

Commented:
im just using my compiler to run it though i tried it through dos also
maybe show us the command u typed ?

Author

Commented:
i just tried running dos again using java -cp {DIR} matrix as suggested and it gave me the same error

Author

Commented:
whoa i acually kind of got it to work

i typed: java -cp c:\windows matrix

Author

Commented:
ok great its working now i just have to fix the run paramiters in my compilier kool

Author

Commented:
thanks for your help kokchoon78 you helped me fix it thanks ALOT you have no clue how much that was bugging me!!
:)

Author

Commented:
im having problems getting textpad configured though, it doesnt find javac.exe now. can you help kokchoon78?

Author

Commented:
as it turns out i dont HAVE javac.exe anymore only javaw.exe

Author

Commented:
as it turns out i dont HAVE javac.exe anymore only javaw.exe

Author

Commented:
as it turns out i dont HAVE javac.exe anymore only javaw.exe

Author

Commented:
as it turns out i dont HAVE javac.exe anymore only javaw.exe
Hi,

   try to set path at the Autoexec.bat

Start - run - type in "sysedit" then add the jdk's path to the "set path", example :

set path=%path%;C:\j2sdk1.4.1\bin

then restart your PC.

then try to compile with your text path....

if it doesn't work, then try to configure the textpad "java compiler", add the initial path will the jdk's path {jdk_path}\bin

hth,

Author

Commented:
as it turns out i dont HAVE javac.exe anymore only javaw.exe
Hi,

   you can create a new tool by :

Configure - Preferences - tools - add - program , then find the javac.exe. Click ok or apply to confirm.

Then u can use the new java compiler from the Tools menu.

hth,

Author

Commented:
at the moment the only way i can get the thing to work is through the dos prompt i can't get textpad to run it right(i fixed the javac.exe it got deleted somehow)

Author

Commented:
at the moment im going to bed (12:25 a.m. on a school night) but please help me if you can i'll check tomorrow

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial