im trying to compile a java file in my computer...and it wil not work...its my first time doin it here...

my problem was..i cant compile any java file...


this will only appear


java.lang.NoClassDefFoundError: mynote/java
Exception in thread "main"

Recommended Answers

All 8 Replies

This is due to a missing or incorrect classpath. Classpath tells where to find the files required to compile your program. You specify it by either setting an environment variable CLASSPATH or by using the -cp switch on the javac command:

javac -cp ./;c:/myProjectDir;c:/otherFilesDir MyProgram.java

If it is a single file with no other dependencies, you can compile it from within the directory containing the java file without setting the classpath, but you will need to have the jdk/bin directory on your system path or use the full path to javac to invoke it.

hello can i ask for a help....i dont know how to continue with my project..please help me with this..i my project is to make a sample editor that counts the characters, consonants, vowels,symbols and spaces..can u please help me with this...my code as of now..still the layout..

import java.awt.*;
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import java.util.*;



public class gui2 extends JFrame
{
private static final int WIDTH = 1500;
private static final int HEIGHT = 1500;


private JLabel characL, vowL, consoL, spacesL, symL;
private JTextField characTF, vowTF, consoTF, spacesTF, symTF;
private JTextArea ATA;



public gui2()
{
characL = new JLabel("Characters:", SwingConstants.LEFT);
vowL = new JLabel("Vowels: ", SwingConstants.LEFT);
consoL = new JLabel("Consonants: ", SwingConstants.LEFT);
spacesL = new JLabel("Spaces:", SwingConstants.LEFT);
symL = new JLabel("Symbols:", SwingConstants.LEFT);


characTF = new JTextField(20);
vowTF = new JTextField(20);
consoTF = new JTextField(20);
spacesTF = new JTextField(20);
symTF = new JTextField(20);


ATA = new JTextArea();
setTitle("Jesse's Text Editor");
Container pane = getContentPane();


setLayout(null);


pane.add(ATA);
pane.add(characL);
pane.add(characTF);
pane.add(vowL);
pane.add(vowTF);
pane.add(consoL);
pane.add(consoTF);
pane.add(spacesL);
pane.add(spacesTF);
pane.add(symL);
pane.add(symTF);



ATA.setSize(1000,600);
characL.setSize(100,50);
characTF.setSize(75,50);
vowL.setSize(100,50);
vowTF.setSize(75,50);
consoL.setSize(100,50);
consoTF.setSize(75,50);
spacesL.setSize(100,50);
spacesTF.setSize(75,50);
symL.setSize(100,50);
symTF.setSize(75,50);


ATA.setLocation(80,20);
characL.setLocation(1,700);
characTF.setLocation(80,700);
vowL.setLocation(200,700);
vowTF.setLocation(300,700);
consoL.setLocation(400,700);
consoTF.setLocation(500,700);
spacesL.setLocation(600,700);
spacesTF.setLocation(700,700);
symL.setLocation(800,700);
symTF.setLocation(900,700);


ATA.setBorder(BorderFactory.createLineBorder(Color.black));
ATA.setColumns(50);
ATA.setRows(20);


setSize(WIDTH, HEIGHT);
setVisible(true);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args)
{
new gui2();
}


}

the code is not good..^^but it runs..still the layout...

NoClassDefFound isn't thrown from the compiler, only from the runtime...

So you probably did not in fact compile your class, or indeed forgot to include it on the classpath when trying to execute it.

how can i get the result from a TextArea and place it on a TextField??....anyone who knows?

getSelectedText(); setText(); should do the trick.
just go through the api's

DO AS FOLLOWING FOR SETTING CLASSPATH:

Setting classpath in jdk 1.6.0


1. install the JDK1.6 from the installation directory
2. Please keep the default path of installation while installing the JDK
generally it would be in the "program files" directory of
System drive. If the system drive is C: then
JDK would be installed at c:\program files\java\jdk1.6 folder

3. right click on "my computer" icon on the desktop.
4. click the property sub menu
5. click the "advanced" tag on the dialog box
6. click on "environment parameters"
7. a dialog box will appear.
look for "system variables" list at the bottom of the dialog box.
8. find out the parameter "path" in the list
9. after selecting the path, click on the edit button
10.a message box will appear with the name "path" and current path value in the bottom text box.
11. append the path of java bin folder with the existing path
the path of java bin folder would be (is installed with default path )

C:\Program Files\Java\jdk1.6.0\bin
append the above path with the existing path
then click OK
12.Now Look for the classpath parameter in the system variable list again.
if No "classpath" parameter is available then
create a new one by clicking "new" button. In the "variable name"
text box give the name "CLASSPATH" and in the
"variable value" text box give the following (if default installation path is choosen)
;.;C:\Program Files\Java\jdk1.6.0\jre\lib\rt.jar
otherwise if the CLASSPATH parameter is already available then
just click the edit button by selecting the existing CLASSPATH and
then append the above CLASSPATH with the exiting one.
click OK

Next

jTextField returns a object
You can get string from jTextField by jTextField.getText.toString()

set path of java home directory and bin directory separately in environment variable

problem in main

should be

public static void main(String[]args)
{
gui2 myprogram=new gui2();
myprogram.setVisible(true);
myprogram.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myprogram.setSize(blah2,blah2);
}

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.