0

i updated version of java from jdk6 to java7 but i am facing a serious problem whenever i execute any java file outside the bin directory it shows class not found.while in bin directory it executes however i have included classpath and path.javac compiles the java file and java class also exist in same directory but java can't execute the class file.i searched it got something like java -cp . classfilename but it also fails by saying illegal argument cp.please help. here is the image it is my java file

     <pre>    
      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;
      import java.io.*;

      public class MotionDetector extends JFrame 
      {
          // GUI components
       private MotionPanel motionPanel;


         public MotionDetector()
          {
         super("Motion Detector");

            Container c = getContentPane();
            c.setLayout( new BorderLayout() );   

            motionPanel = new MotionPanel(); // the sequence of pictures appear here
            c.add( motionPanel, BorderLayout.CENTER);

           addWindowListener( new WindowAdapter() {
           public void windowClosing(WindowEvent e)
          { motionPanel.closeDown();    // stop snapping pics
            System.exit(0);
           }
          });
         setResizable(false);
             pack();  
         setLocationRelativeTo(null);
           setVisible(true);
         }
         public static void main( String args[] )
            {  new MotionDetector();  }
          }

C:\MotionDetection>javac MotionDetector.java

C:\MotionDetection>java MotionDetector
Can't find class MotionDetector

6
  • What package is MotionDetector in?
    – Mike B
    Jan 28, 2014 at 21:26
  • Is "MotionDetector.class" in that directory? Does it have any package name (for instance, is the class actually com.example.MotionDetector? Jan 28, 2014 at 21:27
  • I have the same problem with classes that begins with public,
    – java-love
    Jan 28, 2014 at 21:28
  • Please post the full and exact command that you used and the full output that you got. The image is 180x100 pixels so unreadable, but you need to post it as text in your question because links go stale/rot. Jan 29, 2014 at 0:35
  • @DavidConrad yes "MotionDetector.class" is in the directory...this problem is common for all java program ,even helloworld program not executing outside bin.
    – ajay154
    Jan 29, 2014 at 23:13

2 Answers 2

0

What package is MotionDetector in? If it's not in the default package you'll have to invoke it from the directory containing the package. For example if it's in package MotionDetection then you would have to run it from C:\ like this: java MotionDetection.MotionDetector

0
0

Just check your hello programe in bin directory. If it runs in bin then problem is there in your class path. So now check it outside the bin by setting set path=your path (without semicolon). If it runs after setting path.thn check that you have set bin folder path in enviornment variable.

If it is set still error is comming then check all path's in path under enviornment variable where u have set. Now you will find one older path is also there befor your new path. Change that path or remove.

Always remember windows check for the path from left side. If you have set path at end by semicolon and if any old path is present at left side then that old path is taken from left side.

Now you got what is actual problem

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.