0

I have error while running this below code:

import java.awt.*;
import javax.swing.*;

import org.fife.ui.rtextarea.*;
import org.fife.ui.rsyntaxtextarea.*;

public class TextEditorDemo extends JFrame {

   private static final long serialVersionUID = 1L;


   public TextEditorDemo() {

      JPanel cp = new JPanel(new BorderLayout());

      RSyntaxTextArea textArea = new RSyntaxTextArea();
      textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVA);
      RTextScrollPane sp = new RTextScrollPane(textArea);
      cp.add(sp);

      setContentPane(cp);
      setTitle("RSyntaxTextArea 1.4 - Example 1 - Text Editor Demo");
      setDefaultCloseOperation(EXIT_ON_CLOSE);
      pack();
      setLocationRelativeTo(null);

   }

   public static void main(String[] args) {
      // Start all Swing applications on the EDT.
      SwingUtilities.invokeLater(new Runnable() {
         public void run() {
            new TextEditorDemo().setVisible(true);
         }
      });
   }
}

When i run using java -classpath rsyntaxtextarea.jar;. TextEditorDemo, i'm not getting the output. i'm getting error instead as :

Exception in thread "main" java.lang.NoClassDefFoundError: TextEditorDemo
Caused by: java.lang.ClassNotFoundException: TextEditorDemo
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: TextEditorDemo.  Program will exit.

Can anyone help! This example was taken from, RSyntaxTextArea

2
  • 6
    And what are you getting? Commented Apr 20, 2011 at 13:13
  • What error do you get if you run it without any -classpath option? Commented Apr 20, 2011 at 14:33

2 Answers 2

1

This is a problem with the classpath.

java -classpath rsyntaxtextarea.jar;. TextEditorDemo

As presently set up, the vm will expect to find "TextEditorDemo.class" in the same directory as you are running "java" from, and that "rsyntaxarea.jar" is also in that directory. Check that these files are indeed in the current directory. If not, add the needed path information to the jar, and the location of the TextEditorDemo.class file.

EDIT: The original classpath has ";." at the end - the question has been edited and this removed. The ;. is necessary so that classes are loaded from the current directory.

Sign up to request clarification or add additional context in comments.

1 Comment

Everything is present in the same directory only!
1

Your classpath is wrong. It will only find class in the jar file. To know how to set classpath to a jar file and to your class look at my answer in this question: compile sample.java and jgraph_5.8.3.1.jar

3 Comments

But i have used for compilation javac -classpath rsyntaxtextarea.jar TextEditorDemo.java. It works well, there is a problem with run only
rsyntaxtextarea.jar is present in the same folder where my Program reside!
@GroovyUser: When you run java command with a classpath it checks in that classpath only. Not in the folder where you are running it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.