0

I started using JDBC so I went to Classpath, changed it to classpath of OracleDriver and program compiled. There was classpath set earlier there which I did not bother to check.Now, the program can compile but I am not able to run it.This is the error message I am getting:

Could not find or load main class 'classname that I am trying to run'

Any idea what's wrong?

systemdebt
  • 4,589
  • 10
  • 55
  • 116
  • 1
    how do you run it ? what does your classlook like – jmj Aug 08 '14 at 23:13
  • I run it using command prompt.I wrote program in Notepad and saved it to desktop. – systemdebt Aug 08 '14 at 23:14
  • 2
    possible duplicate of [What does "Could not find or load main class" mean?](http://stackoverflow.com/questions/18093928/what-does-could-not-find-or-load-main-class-mean) – PM 77-1 Aug 08 '14 at 23:15

1 Answers1

2

After you compile, there are generated .class files that get made from the .java files.

When you want to run, you need the generated .class files on the path, so find the directory where they live, and add that directory to the class path.

Note that if you define a class as

package com.corp.myproduct;

public class Sifter {
}

It will generate to a path of

<root>/com/corp/myproduct/Sifter.class

or on windows

<root>\com\corp\myproduct\Sifter.class

where root is the "top level directory" of the compiled output. You don't add <root>/com/corp/myproduct/ in such a case to the classpath, you just add <root>.

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138
  • my .class files are created exactly where I save my program – systemdebt Aug 08 '14 at 23:27
  • @Simrankaur And I will bet that you don't have the root of that directory tree on your classpath. Just because it is in the same place as the source files doesn't mean that it will be on the classpath. – Edwin Buck Aug 08 '14 at 23:32